Cron Script to Restart Apache/MySQL on Crash (Centos/RHEL)
April 6th, 2011
If you need to auto restart Apache and MySQL in case one or both are crashed, just schedule this SH script on Centos (RHEL) in your cron section.
Save the code section below as restart_apache_mysql.sh in your home directory.
Give the file permissions, so root can execute the script and schedule it in Cron.
#!/bin/bash
# APACHE SECTION
RESTART="/etc/rc.d/init.d/httpd restart"
PGREP="/usr/bin/pgrep"
HTTPD="httpd"
$PGREP ${HTTPD}
if [ $? -ne 0 ]
then
$RESTART
fi
# MYSQL SECTION
RESTARTM="/etc/rc.d/init.d/mysqld restart"
MYSQLD="mysqld"
$PGREP ${MYSQLD}
if [ $? -ne 0 ]
then
$RESTARTM
fi
In Webmin, you can schedule above script to run every minute, as follows:

Enjoy.
Entry Filed under: English Blog
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed