Bash Script Restart Apache if the Service is down

#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# RHEL / CentOS / Fedora Linux restart command
# RESTART="/sbin/service httpd restart"
# RHEL / CentOS / cPanel Linux restart command
RESTART="/usr/local/cpanel/scripts/restartsrv_apache" 
# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart" 
#path to pgrep command
PGREP="pidof"
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"
# find httpd pid
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi
exit

Related posts

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *