Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Checking Apache Status

4:25 am on Nov 1, 2006 (gmt 0)

New User

5+ Year Member

joined:Nov 1, 2006
votes: 0

I am planning to write a script that will execute to check if apache is UP and running, and try to restart it automatically if it is down, and will be putting this script to cron and run it every n minutes.

But, I was wondering how I should be checking apache status? Should I make a request to some dummy file, or check the processes via ps -ef, etc? What is the easiest and fastest (hence least costly) way of doing this?


2:59 pm on Nov 1, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 17, 2002
votes: 5

You should be able to check the status with:

/etc/init.d/httpd status

(or whatever your apache start file is)

do that and you'll get a result similar to

httpd (pid 13149 13103 13102 13101 13099 13098 13097 13095 13018 13017 13015 13014 13000 12963 12928 10986) is running...

If you run that command when it is down you'll get:

httpd is stopped

You could easily run the command and pipe and grep the output to detect either running or stopped. If stopped then issue an an httpd start.

An easier alternative is Webmin System and Server Status monitor. You can set the apache status to be checked every minute, hour, day and then run a command such as start apache, email you etc.

[edited by: Frank_Rizzo at 3:00 pm (utc) on Nov. 1, 2006]