Good Day, long enough not blogging on this site. This is my problem when I’m moving some websites into my cloud servers. Sometimes when my traffic going very high MySQL server crashes and I need to run it manually or reboot my server. This is really bad for SEO because my servers uptime will changed.
I am googling about this problem to find solution for resolve this issue and finally I found one is working for me. Here is the steps you need to follow :
Create file (example /etc/startifdown.sh and write this code inside it:
#!/bin/bash#Scripts to start services if not runningps -ef | grep nginx |grep -v grep > /dev/nullif [ $? != 0 ]then/etc/init.d/nginx start > /dev/nullfips -ef | grep php5-fpm |grep -v grep > /dev/nullif [ $? != 0 ]then/etc/init.d/php5-fpm start > /dev/nullfips -ef | grep mysql |grep -v grep > /dev/nullif [ $? != 0 ]then/etc/init.d/mysql start > /dev/nullfi
Save it and chmod 755 for this file to allow it executed. Next step, Manually stop your MySQL server and try to run run this script to make sure it’s worked. If it turn back your MySQL server on then move to next step.
To make this script run every minutes you can put it on crontab job. Type crontab -e and choose your favorites editor…
Done, This cron will run each minute to check if your MySQL server down and then restart it, If your MySQL server is run it will skip to start MySQL. That’s for today, Merry Christmas and Happy New Year everyone!
Similar Posts:
- CRON JOB to Repair and Optimize Database
- PHP: How To Limit Download By IP Address Per Interval
- PHP: How To Blocking Bad Referrer Site
- How To: Created 2 Way SMS Gateway With NowSMS and PHP