# If we ever end up running God / Starling on other environments than production. # we'll have to find a different way to set the values below. STARLING_PORT = 15151 STARLING_HOST = '' RAILS_ENV = 'production' # Based on example from RAILS_ROOT = '/var/www/myapp' def generic_monitoring(w, options = {}) w.start_if do |start| start.condition(:process_running) do |c| c.interval = 10.seconds c.running = false end end w.restart_if do |restart| restart.condition(:memory_usage) do |c| c.above = options[:memory_limit] c.times = [3, 5] # 3 out of 5 intervals end restart.condition(:cpu_usage) do |c| c.above = options[:cpu_limit] c.times = 5 end end 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 # Start 3 workling daemons 0.upto(2) do |num| God.watch do |w| script = "RAILS_ENV=#{RAILS_ENV} #{RAILS_ROOT}/script/workling_client --number #{num}" w.name = "myapp-workling-#{num}" w.group = "myapp-worklings" w.interval = 60.seconds w.start = "#{script} start" w.restart = "#{script} restart" w.stop = "#{script} stop" w.start_grace = 20.seconds w.restart_grace = 20.seconds w.pid_file = "#{RAILS_ROOT}/log/workling#{num}.pid" w.behavior(:clean_pid_file) generic_monitoring(w, :cpu_limit => 25.percent, :memory_limit => 100.megabytes) end end God.watch do |w| w.name = "myapp-starling" w.group = "myapp-starlings" w.interval = 60.seconds w.start = "/usr/bin/starling -d -P #{RAILS_ROOT}/log/starling.pid -q #{RAILS_ROOT}/log/ -p #{STARLING_PORT} -h #{STARLING_HOST}" w.stop = "kill `cat #{RAILS_ROOT}/log/starling.pid`" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.pid_file = "#{RAILS_ROOT}/log/starling.pid" w.behavior(:clean_pid_file) generic_monitoring(w, :cpu_limit => 30.percent, :memory_limit => 30.megabytes) end