Created
May 19, 2013 19:43
-
-
Save robdbirch/5608735 to your computer and use it in GitHub Desktop.
God server transitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def life_cycle(w) | |
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 | |
def server_transitions(w) | |
w.transition(:start, :up) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
end | |
end | |
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 = 5 | |
c.transition = :start | |
end | |
end | |
# init if process is not running | |
w.transition(:up, :init) do |on| | |
on.condition(:process_exits) | |
end | |
life_cycle w | |
end | |
# Example Watch | |
God.watch do |w| | |
w.group = "app_servers" | |
w.name = "app_server" | |
w.start = "#{APP_ROOT}/bin/app_server --log-file #{APP_ROOT}/log/app_server.log" | |
w.start_grace = 5.seconds | |
w.restart_grace = 5.seconds | |
w.log = "#{APP_ROOT}/log/app_server.log" | |
w.interval = 30.seconds | |
w.transition(:init, :start) do |on| | |
on.condition(:dependents_running) do |c| | |
c.interval = 3.seconds | |
end | |
end | |
server_transitions w | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment