Assuming that to want to restart a MySQL server automatically after a crash I would do something like this: set a cronjob which check every 10 minutes if MySql server is on! If not, then run a bash command which will start it (e.g.: Debian/Ubuntu:
service mysql restart).
So, the bash script would be:
Code:
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
echo "MySQL is down.";
sudo service mysql start
else
echo "All is well.";
fi
monitor.sh >>
https://gist.github.com/mheadd/5571023
Then set a cron job run this job every interval you want, in my example 5 minutes:
Code:
*/5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1
Eventually you may want to receive an email to inform you when sql server crash with the following bash script:
Code:
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
mailx -s "Mayday mayday, SQL down!" < /dev/null "myself@maysite";
sudo service mysql start
else
echo "All is well.";
fi