Skip to content

Instantly share code, notes, and snippets.

@steverobbins
Created February 3, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverobbins/70c441b88d03a2aae0b62761e964d0e9 to your computer and use it in GitHub Desktop.
Save steverobbins/70c441b88d03a2aae0b62761e964d0e9 to your computer and use it in GitHub Desktop.
#!/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 steve@steverobbins.com -s 'Prince Lion Heart MySQL has stopped'
else
echo 'MySQL is down but was restarted successfully' | mail steve@steverobbins.com -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