There are several ways to solve the problem of Apache running wild and killing MySQL. It the problem occurs very infrequently, there’s a easy way of restarting MySQL with the use of the crontab. The script even sends a notification email so you know what just happened.
First, SSH into your server:
1 |
ssh root@server-ip |
Create a script file:
1 |
nano mysqlfix.sh |
Paste the following:
1 2 3 4 5 6 7 |
#!/bin/bash PATH=/usr/sbin:/usr/bin:/sbin:/bin if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]] then echo "MySQL restarted for henriksson.me on Digital Ocean" | mail -s "MySQL restarted" markus@henriksson.me sudo service mysql start fi |
Press CTRL + O to save, and CTRL + X to exit.
Give execute permission to your script:
1 |
chmod +x mysqlfix.sh |
Edit the Crontab:
1 |
crontab -e |
Paste the following:
1 |
* * * * * /root/mysqlfix.sh |
Press CTRL + O to save, and CTRL + X to exit.
To see if it works, type the following:
1 |
service mysql stop |
In case the service doesn’t start, just start it manually with the following:
1 |
service mysql start |
nice
ty