Search code examples
ruby-on-railsrubyredisgod

God configuration file to monitor existing processes?


I am monitoring my redis server using God (a Ruby gem). However, my existing server may already has an instance of redis up. How can I be sure it monitors the existing Redis server process that is already up?

This is my God file for redis:

rails_root = ENV['RAILS_ROOT']
redis_root = "/usr/local/bin"

# Redis
%w{6379}.each do |port|
  God.watch do |w|
    w.name          = "redis"
    w.interval      = 30.seconds
    w.start         = "#{redis_root}/redis-server /etc/redis/redis.conf"
    w.stop          = "#{redis_root}/redis-cli shutdown"
    w.restart       = "#{w.stop} && #{w.start}"
    w.start_grace   = 10.seconds
    w.restart_grace = 10.seconds
    w.log           = File.join(rails_root, 'log', 'redis.log')
    w.keepalive(:memory_max => 5000.megabytes)
    w.start_if do |start|
      start.condition(:process_running) do |c|
          c.interval = 5.seconds
          c.running = false
      end
    end
  end
end

Solution

  • To answer this question:

    I put a w.pid_file = "SOMETHING" in my God file, and made sure this PID file was also set in the configuration file for Redis.