Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #-------------------------------------------------
- # Turn on debug mode
- set -x
- #-------------------------------------------------
- # General Variables
- URL="http://seekeraftertruth.com/"
- BASEPATH="/home/admin/scripts/"
- LOGSOURCE="satstatus.log"
- TIMESTAMP=`date +%r`
- #-------------------------------------------------
- # Test Site Availability
- #-------------------------------------------------
- if [ ! -f "$URL" ]
- then
- touch $BASEPATH$SATSTATUS
- HTTP_PRE_STATUS=`wget --spider -nv $URL -o $BASEPATH$LOGSOURCE`
- HTTP_STATUS=`cat $BASEPATH$LOGSOURCE | /usr/bin/awk '{print $5}'`
- else
- truncate -s0 $BASEPATH$LOGSOURCE
- HTTP_PRE_STATUS=`wget --spider -nv $URL -o $BASEPATH$LOGSOURCE`
- HTTP_STATUS=`cat $BASEPATH$LOGSOURCE | /usr/bin/awk '{print $5}'`
- fi
- #-------------------------------------------------
- # Check PHP5-FPM status
- #-------------------------------------------------
- if [ "$HTTP_STATUS" != "200" ]
- then
- # Restart the crashed PHP5-fpm service
- service php5-fpm restart
- #-------------------------------------------------
- # Log Handling Variables During Failure Condition
- #-------------------------------------------------
- LOGPATH="/srv/www/seekeraftertruth.com/logs/"
- LOGPREFIX="php5-fpm-"
- LOGSUFFIX=".log"
- LOGDATE="php5-fpm-`(date +%F)`.log"
- LOGOUTPUT=`cat $BASEPATH$LOGSOURCE | grep -v ":" `
- LOGMAKE=`echo "Wget reported" $LOGOUTPUT "at" $TIMESTAMP >> $LOGPATH$LOGDATE`
- LOGDAY=`echo $LOGPATH$LOGDATE | awk -F\- '{print $5}' | cut -d"." -f1`
- LOGMONTH=`echo $LOGPATH$LOGDATE | awk -F\- '{print $4}'`
- LOGYEAR=`echo $LOGPATH$LOGDATE | awk -F\- '{print $3}'`
- LOGFILEYESTERDAY="$LOGPATH$LOGPREFIX`date -d "-1 days" +"%Y-%m-%d"`$LOGSUFFIX"
- LOGYESTERDAY=`date -d "-1 days" +"%Y%m%d"`
- LOGTODAY=`(date +%F)`
- LOGRECORD="$LOGYEAR$LOGMONTH$LOGDAY"
- LOGCOUNT=`grep -c "" $LOGPATH$LOGDATE`
- LOGFLAG="${BASEPATH}WGET_FLAG_DO_NOT_DELETE_`(date +%F)`"
- FLAGDATE=`stat --format "%y" $LOGPATH$LOGDATE | awk -F" " '{print $1}' | sed 's/-//g'`
- CHOWNUSER="www-data"
- CHOWNGRP="adm"
- # Create a log occurrence at /srv/www/seekeraftertruth.com/logs/php5-fpm-(date +%F)
- $LOGMAKE
- #-------------------------------------------------
- # Email Variables Initialized in Failure Condition
- #-------------------------------------------------
- SUBJECT="[$LOGCOUNT times] PHP5-FPM restarted"
- # Email from ?
- EMAIL_FROM="php5fpm-report@seekeraftertruth.com"
- # Email to ?
- EMAIL_TO="satfeed@live.com"
- # Email text/message
- EMAILMESSAGE="PHP5-FPM restarted $LOGCOUNT times on $LOGDAY-$LOGMONTH-$LOGYEAR"
- if [ -f "$LOGFILEYESTERDAY" ]
- then
- if [ ! -f "$LOGFLAG" ]
- then
- # echo "Going to email log file for $LOGPATH$LOGDATE"
- echo $EMAILMESSAGE | mail -s "$SUBJECT" "$EMAIL_TO" -a "Reply-To: $EMAIL_FROM" < $LOGPATH$LOGDATE
- touch $LOGFLAG
- chown $CHOWNUSER:$CHOWNGRP "$LOGPATH$LOGDATE"
- chown $CHOWNUSER:$CHOWNGRP "$LOGFLAG"
- fi
- fi
- if [ ${FLAGDATE} -eq ${LOGYESTERDAY} ]
- then
- rm $LOGFLAG
- fi
- fi
Add Comment
Please, Sign In to add comment