Skip to content

Instantly share code, notes, and snippets.

@emilcarr
Last active April 1, 2021 17:58
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 emilcarr/fd912bdfedd9121d7ca2bbafc389e612 to your computer and use it in GitHub Desktop.
Save emilcarr/fd912bdfedd9121d7ca2bbafc389e612 to your computer and use it in GitHub Desktop.
#!/bin/bash
# /etc/cron.d/mysql_watch_online
# Test the database connection and restart on failure
mysql -e '\q'
if [ $? != 0 ]; then
echo `systemctl status mysql` | mail -s "MySQL Databse experience issues | `hostname`" your@email.com
systemctl restart mysql
fi
# Execute every 5 minutes
*/5 * * * * /etc/cron.d/mysql_watch_online
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment