1 # This example shows how you might keep a local development Rails server up
2 # and running on your Mac.
5 # god -c /path/to/events.god
7 RAILS_ROOT = ENV['GOD_TEST_RAILS_ROOT']
9 %w{3002}.each do |port|
11 w.name = "local-#{port}"
12 w.interval = 5.seconds
13 w.start = "mongrel_rails start -p #{port} -P #{RAILS_ROOT}/log/mongrel.#{port}.pid -c #{RAILS_ROOT} -d"
14 w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.#{port}.pid -c #{RAILS_ROOT}"
15 w.pid_file = File.join(RAILS_ROOT, "log/mongrel.#{port}.pid")
16 w.log = File.join(RAILS_ROOT, "log/commands.#{port}.log")
18 # clean pid files before start if necessary
19 w.behavior(:clean_pid_file)
21 # determine the state on startup
22 w.transition(:init, { true => :up, false => :start }) do |on|
23 on.condition(:process_running) do |c|
28 # determine when process has finished starting
29 w.transition([:start, :restart], :up) do |on|
30 on.condition(:process_running) do |c|
35 on.condition(:tries) do |c|
42 # start if process is not running
43 w.transition(:up, :start) do |on|
44 on.condition(:process_exits)
47 # restart if memory or cpu is too high
48 w.transition(:up, :restart) do |on|
49 on.condition(:memory_usage) do |c|
51 c.above = 50.megabytes
55 on.condition(:cpu_usage) do |c|
61 on.condition(:http_response_code) do |c|
66 c.timeout = 10.seconds
73 on.condition(:flapping) do |c|
74 c.to_state = [:start, :restart]
77 c.transition = :unmonitored
78 c.retry_in = 10.minutes
80 c.retry_within = 2.hours