Created
May 29, 2015 19:00
-
-
Save andrewchilds/015efc22dd7decb6d0e7 to your computer and use it in GitHub Desktop.
mysqlrestarter
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 | |
# Run every minute using cron: | |
# */1 * * * * /path/to/mysqlrestarter > /dev/null 2>&1 | |
serverName="website.com" | |
adminEmail="[email protected]" | |
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
UP=$(service mysql status | grep 'mysql start/running' | wc -l); | |
if [ "$UP" -eq 0 ]; then | |
echo "MySQL is down: $(service mysql status)" | mail -s "Restarting MySQL on $serverName" -r "no-reply@$serverName" $adminEmail | |
service mysql start | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment