#!/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 |
This comment has been minimized.
This comment has been minimized.
I had to set the PATH variable to include /sbin in the crontab for the script to be run successfully by cron.
|
This comment has been minimized.
This comment has been minimized.
I don't know which distro are you using but to me it seems a better version is:
That is even more logical because if it's not running it should not print out anything (-eq 0). If it is, it should print out something (is not equal to zero). Your script starts up mysql if there is more than one instance running. |
This comment has been minimized.
This comment has been minimized.
Isn´t it better to check if it is running by using this?
|
This comment has been minimized.
This comment has been minimized.
Unfortunately that haven't worked for me. This worked well:
And to check this every minute, I have added a cron job as: Hope that helps someone! |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Worked for me in Debian |
This comment has been minimized.
This comment has been minimized.
awesome! |
This comment has been minimized.
This comment has been minimized.
The original script does not work on my system. MySql runs 2 processes, so UP gets set to 2 and it thinks the service is not running. |
This comment has been minimized.
This comment has been minimized.
If you are using Redhat (RHEL)/Fedora/CentOS
Don't forget to give the file executable permission |
This comment has been minimized.
This comment has been minimized.
For me, i used this:
and then |
This comment has been minimized.
Run this script every 5 minutes using a cron job like this one: