Skip to content

Instantly share code, notes, and snippets.

@andrewchilds
Created May 29, 2015 19:00
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 andrewchilds/015efc22dd7decb6d0e7 to your computer and use it in GitHub Desktop.
Save andrewchilds/015efc22dd7decb6d0e7 to your computer and use it in GitHub Desktop.
mysqlrestarter
#!/bin/bash
# Run every minute using cron:
# */1 * * * * /path/to/mysqlrestarter > /dev/null 2>&1
serverName="website.com"
adminEmail="me@example.com"
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