[Ruby] One line to save God

Par défaut

We’ve had unexpecting interruptions in our Feevy updaters last weeks, and the error (which is still strange) came from inside God, it was unable to decide if a process was still running.

If you’ve the same kind of problem, with your god logging showing « kill: 1: No such process« , then change the exists? method in /usr/local/lib/ruby/gems/1.8/gems/god-0.5.0/lib/god/system/process.rb file, gem path might not be the same on your system.

# Return true if this process is running, false otherwise
def exists?
    # system("kill -0 #{@pid} &> /dev/null")
    ps_int('rss') != 0

Here is our configuration if some people can find where this line is causing problem: Ubuntu Gutsy, Ruby 1.8.6, God 0.5

[Ruby] God monitor

Par défaut

Update: this script, from September 2007, is a bit out-dated, you can get more info on official God gem website.

Looking for a ruby programmer? Contact me

After many ways to monitor Feevy updaters, we’re finally using God gem today to manage everything with Ruby on many platforms.

Documentation is really clear, and it’s easy to adapt it to your own code. The nicest point was to be able to control our non-daemonized updaters, and monitor them all in the same tool.

Here is our script:

require 'rubygems'
require 'god'

ROOT = File.dirname(__FILE__)

God.init do |god|
  god.pid_file_directory = "#{ROOT}/pids"

[*0...20].each do |updater|
  God.watch do |w|
    # watch with no pid_file attribute set
    w.name = "updater_#{updater}"
    w.interval = 30.seconds # default
    w.start = "ruby #{ROOT}/updater.rb"
    w.grace = 10.seconds


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

    w.restart_if do |restart|
      restart.condition(:memory_usage) do |c|
        c.above = 150.megabytes
        c.times = [3, 5] # 3 out of 5 intervals

      restart.condition(:cpu_usage) do |c|
        c.above = 50.percent
        c.times = 5

[updated]: thanks to apeiros on irc://#ruby@irc.freenode.net for quick array initialization tips!