more diagnostics
[god.git] / examples / gravatar.god
bloba676ddc94268b61ebe23508e86145c986f087d91
1 # run with:  god -c /path/to/gravatar.god
2
3 # This is the actual config file used to keep the mongrels of
4 # gravatar.com running.
6 RAILS_ROOT = "/Users/tom/dev/gravatar2"
8 %w{8200 8201 8202}.each do |port|
9   God.watch do |w|
10     w.name = "gravatar2-mongrel-#{port}"
11     w.interval = 30.seconds # default      
12     w.start = "mongrel_rails start -c #{RAILS_ROOT} -p #{port} \
13       -P #{RAILS_ROOT}/log/mongrel.#{port}.pid  -d"
14     w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.#{port}.pid"
15     w.restart = "mongrel_rails restart -P #{RAILS_ROOT}/log/mongrel.#{port}.pid"
16     w.start_grace = 10.seconds
17     w.restart_grace = 10.seconds
18     w.pid_file = File.join(RAILS_ROOT, "log/mongrel.#{port}.pid")
19     
20     w.behavior(:clean_pid_file)
22     w.start_if do |start|
23       start.condition(:process_running) do |c|
24         c.interval = 5.seconds
25         c.running = false
26       end
27     end
28     
29     w.restart_if do |restart|
30       restart.condition(:memory_usage) do |c|
31         c.above = 150.megabytes
32         c.times = [3, 5] # 3 out of 5 intervals
33       end
34     
35       restart.condition(:cpu_usage) do |c|
36         c.above = 50.percent
37         c.times = 5
38       end
39     end
40     
41     # lifecycle
42     w.lifecycle do |on|
43       on.condition(:flapping) do |c|
44         c.to_state = [:start, :restart]
45         c.times = 5
46         c.within = 5.minute
47         c.transition = :unmonitored
48         c.retry_in = 10.minutes
49         c.retry_times = 5
50         c.retry_within = 2.hours
51       end
52     end
53   end
54 end