Skip to content

Instantly share code, notes, and snippets.

@digitalhobbit
Created February 21, 2009 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save digitalhobbit/67816 to your computer and use it in GitHub Desktop.
Save digitalhobbit/67816 to your computer and use it in GitHub Desktop.
# 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 = '<my ip address>'
RAILS_ENV = 'production'
# Based on example from <http://railscasts.com/episodes/130-monitoring-with-god>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment