Created
February 20, 2015 15:52
-
-
Save djaney/270e6799e6aaa2a288dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #ver. 2 | |
| ##this script will check mysql and apache | |
| ##if that service is not running | |
| ##it will start the service and send | |
| ##an email to you | |
| ##set your email address | |
| EMAIL="xxxxxxxxxxxx" | |
| ##list your services you want to check | |
| SERVICES=( 'hhvm' 'nginx' 'mysql' ) | |
| #### DO NOT CHANGE anything BELOW #### | |
| for i in "${SERVICES[@]}" | |
| do | |
| ###IF SERVICE IS NOT RUNNING#### | |
| service $i status; | |
| STATS=$(echo $?) | |
| echo $STATS | |
| if [[ $STATS != 0 ]] | |
| then | |
| ##TRY TO RESTART THAT SERVICE### | |
| service $i restart | |
| ##IF RESTART WORKED### | |
| service $i status; | |
| RESTART=$(echo $?) | |
| if [[ $RESTART == 0 ]] | |
| then | |
| ##SEND AN EMAIL### | |
| MESSAGE="$(tail -5 /var/log/$i/error.log)" | |
| SUBJECT="$i down -but restarted- on $(hostname) $(date) " | |
| echo " $i $MESSAGE " | mail -s "$SUBJECT" "$EMAIL" | |
| else | |
| ##IF RESTART DID NOT WORK SEND A DIFFERENT EMAIL### | |
| MESSAGE="$(tail -5 /var/log/$i/error.log)" | |
| SUBJECT="$i down on $(hostname) $(date) " | |
| echo " $i $MESSAGE . I tried to restart but it did not work" | mail -s "$SUBJECT" "$EMAIL" | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment