Monitoring apache with god

According to the site: God is an easy to configure, easy to extend monitoring framework written in Ruby.

While god is mainly intended for monitoring mongrels it is also a great way to keep an eye on apache itself. Below is our config for watching apache.

%w{80}.each do |port| do |w| = "apache"
w.interval = 30.seconds # default
w.start = "apachectl start"
w.stop = "apachectl stop"
w.restart = "apachectl restart"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds

w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false


The code is pretty self-explanatory. We’re just looking to make sure apache is up every 5 seconds.

After gem installing god, save the configuration file anywhere you want and kick if off with this command:

god -c /path/to/your_conf.god

That’s it. To test, kill apache and in less than 5 seconds it will be back up and running.


    caleb |

    that’s pretty cool.

    Christian Romney |

    You probably don’t need the port loop.

    david |

    So, this doesn’t actually monitor apache, it just executes apachectl start every five seconds, so yeah, apache is always running…

    Try: god -c /path/to/your_conf.god -D
    The -D makes god not go into the background, and you can watch it try to restart apache constantly.

    Adding a line like the following will allow God to check the pid of the process before determining it is not running:
    w.pid_file = ‘/var/run/’


    Claudia |

    good always been easy to configure the apache, just follow the steps and restart it and you can get your server configured ..but you need to monitor it everytime to ensure its uptime..