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|
  God.watch do |w|
    w.name = "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
      end
    end
  end
end

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.