Thursday, July 3, 2008

Shell script to auto restart web server httpd if it goes down

First set the crontab as follows
*/5 * * * * /path/to/ >/dev/null 2>&1

Shell script as follows

# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
RESTART="service httpd restart"

# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"

#path to pgrep command

# find httpd pid
$PGREP httpd

if [ $? -eq 0 ]
# restart apache
fiA better and more reliable solution is monit monitoring software for restarting services such as mysql, apache and sendmail under UNIX

1 comment:

carmela kailinit said...

Thanks For this Tutorial now i know how this Shell Script works
Please visit my site and Rate my Skills on Design?

Visit my Website