added cpu_usage condition and local.god example
[god.git] / examples / local.god
blob8c8c7dcb9a47189fe69b8941744b5f582aac38b0
1 # This example shows how you might keep a local development Rails server up
2 # and running on your Mac.
4 RAILS_ROOT = "/Users/tom/dev/gravatar2"
6 God.meddle do |god|
7   god.interval = 60 # seconds
8   
9   god.watch do |w|
10     w.name = "local-3000"
11     w.cwd = RAILS_ROOT
12     w.start = "mongrel_rails start -P ./log/mongrel.pid -d"
13     w.stop = "mongrel_rails stop -P ./log/mongrel.pid"
14     w.grace = 5
15     
16     pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
17   
18     w.start_if do |start|
19       start.condition(:process_not_running) do |c|
20         c.pid_file = pid_file
21       end
22     end
23     
24     w.restart_if do |restart|
25       restart.condition(:memory_usage) do |c|
26         c.pid_file = pid_file
27         c.above = (50 * 1024) # 50mb
28         c.times = [3, 5]
29       end
30       
31       restart.condition(:cpu_usage) do |c|
32         c.pid_file = pid_file
33         c.above = 10 # percent
34         c.times = [3, 5]
35       end
36     end
37   end
38 end