how to auto restart apache when it goes down

From WebHostingNeeds.com
Revision as of 13:40, 21 February 2008 by Admin (talk | contribs) (New page: Create a shell script with following <pre> #!/bin/sh # # Apache Process Monitor # checkapache=`ps ax | grep -v grep | grep -c httpd` if [ $checkapache -le 0 ] then /usr/local/apache/bin/a...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Create a shell script with following

#!/bin/sh
#
# Apache Process Monitor
#
checkapache=`ps ax | grep -v grep | grep -c httpd`
if [ $checkapache -le 0 ]
then
/usr/local/apache/bin/apachectl startssl
fi

Save it as /root/utils/monitor-apache.sh

Then set cronjob


*/5 * * * * sh /root/utils/monitor-apache.sh >/dev/null 2>&1

This will check Apache every 5 minutes, and if no httpd processes are running it will automatically restart the daemon.