# run with: god -c /path/to/god.conf # RAILS_ROOT = "<%= current_path %>" RAILS_ENV = "<%= rails_env %>" LOCAL_BIN = "/usr/local/bin" God.watch do |w| w.name = 'mysql-process' w.group = 'mysql' w.interval = 30.seconds # default w.start = "/etc/init.d/mysqld start" w.stop = "/etc/init.d/mysqld stop" w.restart = "/etc/init.d/mysqld restart" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.pid_file = '/var/run/mysqld/mysqld.pid' w.behavior(:clean_pid_file) w.start_if do |start| start.condition(:process_running) do |c| c.interval = 5.seconds c.running = false end end # lifecycle w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end God.watch do |w| w.name = 'apache-process' w.group = 'web' w.interval = 30.seconds # default w.start = "/etc/init.d/httpd start" w.stop = "/etc/init.d/httpd stop" w.restart = "/etc/init.d/httpd restart" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.pid_file = '/var/run/httpd.pid' w.behavior(:clean_pid_file) w.start_if do |start| start.condition(:process_running) do |c| c.interval = 5.seconds c.running = false end end # lifecycle w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end God.watch do |w| w.name = 'starling-process' w.group = 'starlings' w.interval = 30.seconds # default w.start = "#{LOCAL_BIN}/starling -d -l /var/log/starling.log" w.stop = "kill `cat /var/run/starling.pid`" w.start_grace = 20.seconds w.restart_grace = 20.seconds w.pid_file = '/var/run/starling.pid' w.behavior(:clean_pid_file) w.start_if do |start| start.condition(:process_running) do |c| c.interval = 5.seconds c.running = false end end # lifecycle w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end (<%= dispatcher_ports %>).each do |port| God.watch do |w| w.name = "msc-mongrel-#{port}" w.group = 'mongrels' w.interval = 30.seconds # default w.start = "cd #{RAILS_ROOT}; #{LOCAL_BIN}/mongrel_rails start -e #{RAILS_ENV} -c #{RAILS_ROOT} -p #{port} -P #{RAILS_ROOT}/tmp/pids/mongrel.#{port}.pid -d" w.stop = "cd #{RAILS_ROOT}; #{LOCAL_BIN}/mongrel_rails stop -P #{RAILS_ROOT}/tmp/pids/mongrel.#{port}.pid" w.restart = "cd #{RAILS_ROOT}; #{LOCAL_BIN}/mongrel_rails restart -P #{RAILS_ROOT}/tmp/pids/mongrel.#{port}.pid" w.start_grace = 30.seconds w.restart_grace = 30.seconds w.pid_file = File.join(RAILS_ROOT, "tmp/pids/mongrel.#{port}.pid") w.behavior(:clean_pid_file) w.start_if do |start| start.condition(:process_running) do |c| c.interval = 5.seconds c.running = false end end w.restart_if do |restart| restart.condition(:memory_usage) do |c| c.above = 150.megabytes c.times = [3, 5] # 3 out of 5 intervals end restart.condition(:cpu_usage) do |c| c.above = 70.percent c.times = 5 end end # lifecycle w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end end God.watch do |w| w.name = 'listener-process' w.group = 'listeners' w.interval = 30.seconds # default w.start = "RAILS_ENV=#{RAILS_ENV} #{RAILS_ROOT}/script/workling_starling_client start" w.stop = "RAILS_ENV=#{RAILS_ENV} #{RAILS_ROOT}/script/workling_starling_client stop" w.restart = "RAILS_ENV=#{RAILS_ENV} #{RAILS_ROOT}/script/workling_starling_client restart" w.start_grace = 30.seconds w.restart_grace = 30.seconds w.pid_file = "#{RAILS_ROOT}/tmp/pids/workling.pid" w.behavior(:clean_pid_file) w.start_if do |start| start.condition(:process_running) do |c| c.interval = 5.seconds c.running = false end end # lifecycle w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end