Skip to content

Instantly share code, notes, and snippets.

@BookOfGreg
Created December 3, 2012 21:02
Show Gist options
  • Save BookOfGreg/4197995 to your computer and use it in GitHub Desktop.
Save BookOfGreg/4197995 to your computer and use it in GitHub Desktop.
Nginx God Config
God.watch do |w|
w.name = "nginx"
w.interval = 60.seconds
w.start = "/usr/local/nginx/sbin/nginx"
w.stop = "/usr/local/nginx/sbin/nginx -s stop"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
# determine the state on startup
w.transition(:init, { true => :up, false => :start}) do |on|
on.condition(:process_running) do |c|
c.running = true
end
end
# determine when process has finished starting
w.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.running = true
end
# failsafe
on.condition(:tries) do |c|
c.times = 8
c.within = 2.minutes
c.transition = :start
end
end
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_exits)
end
# restart if no responce on localhost
w.transition(:up, :restart) do |on|
on.condition(:http_response_code) do |c|
c.host = 'localhost'
c.port = port
c.path = '/'
c.code_is = 500
c.timeout = 30.seconds
c.times = [3, 5]
end
end
# lifecycle
w.lifecycle do |on|
on.condition(:flapping) do |c|
c.to_state = [:start, :restart]
c.times = 4
c.within = 5.minutes
c.transition = :unmonitored
c.retry_in = 10.minutes
c.retry_times = 5
c.retry_within = 2.hours
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment