How to Check if Apache Is Up and Restart if Not
I do often monitor server apache status as most often reason of server outages is Apache overload. Some web hosting panels are sending notifications when your server is down; some web services like Alertra.com provide you with different notification options and one of my hosters has his internal monitoring service. But what to do if you need to go anywhere where you can’t get access to your server? You’ll need a cron task that will check whether apache is up and will restart it if not.
I’ve found a solution at a forum. You’ll need a simple shell script and here it is:
#!/bin/sh
run=`ps ax | grep /usr/sbin/httpd | grep -v grep | cut -c1-5 | paste -s -`
if [ "$run" ];
then
echo “Apache is running”
else
/etc/init.d/httpd start
fi
This script will check for a number of running script processes and will try to start apache if it is not running. You should add this script to crontab with any frequency you like. I’d suggest to run it every 3 minutes as it doesn’t cause server load, but your apache stability is vital.
Categories: Apache Performance, Linux Tricks apache check status, apache freetype support, apache on netbook, apache status, check apache is running, check apache running, check apache status, check apache status in linux, check for apache restart, check if apache is running, check if apache is running linux, check if apache is working, check if apache running, check if apache running linux, check status apache, check status of apache, check that apache runs, check to see if apache is running, check whether apache is running linux, checking apache status, checking if apache is running, checking if apache is up, checking that apache is running Linux, determine if apache is running, determine if apache is running on redhat, directadmin apache, directadmin disable apache, how can i tell if apache is running, how do you tell if apache is running, how to check apache is running in linux, how to check apache status, how to check if apache is installed on linux, how to check if apache is running, how to check if apache is running in linux, how to check if apache is running on linux, how to check if apache is running shell, how to check if apache is up and running, how to check if apache is working, how to check if apache running, how to check if apache server is running, how to check if your apache is running, how to check whether apache is running, how to check whether apache is running or not, how to determine if apache is running, how to find if apache is running, how to see if apache is running, how to tell if apache is running, how to test if apache is running, linux apache check is running, linux check apache status, linux check if apache is running, linux check if apache runs, linux how to find if apache is running, monitor apache cron, monitor if apache is running linux, monitoring service, notification options, restart apache cronjob, script to start apache if not running, server apache, server load, server outages, shell script apache monitoring, shell script apache up, test if apache is running