Created
February 3, 2017 18:50
-
-
Save steverobbins/70c441b88d03a2aae0b62761e964d0e9 to your computer and use it in GitHub Desktop.
This file contains 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 | |
MYSQL_RUNNING=0 | |
function checkMysql { | |
/usr/sbin/service mysql status | grep Uptime | |
if [ "$?" == 0 ]; then | |
MYSQL_RUNNING=1 | |
fi | |
} | |
checkMysql | |
if [ "$MYSQL_RUNNING" == 0 ]; then | |
echo 'MySQL is down' | |
/usr/sbin/service mysql start | |
checkMysql | |
if [ -a /root/.mysql-monitor ]; then | |
if [ "$MYSQL_RUNNING" == 0 ]; then | |
echo 'MySQL is down and failed to be restarted' | mail [email protected] -s 'Prince Lion Heart MySQL has stopped' | |
else | |
echo 'MySQL is down but was restarted successfully' | mail [email protected] -s 'Prince Lion Heart MySQL has stopped' | |
fi | |
rm -rf /root/.mysql-monitor | |
fi | |
else | |
echo 'MySQL is up' | |
date > /root/.mysql-monitor | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment