tighten up Hub and add comments
[god.git] / examples / single.god
blobc55372fc76442551a46480b82593de0a294c2df8
1 RAILS_ROOT = "/Users/tom/dev/gravatar2"
3 God.watch do |w|
4   w.name = "local-3000"
5   w.interval = 5.seconds # default
6   w.start = "mongrel_rails start -c #{RAILS_ROOT} -P #{RAILS_ROOT}/log/mongrel.pid -p 3000 -d"
7   w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.pid"
8   w.restart = "mongrel_rails restart -P #{RAILS_ROOT}/log/mongrel.pid"
9   w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
10   
11   # clean pid files before start if necessary
12   w.behavior(:clean_pid_file)
13   
14   # determine the state on startup
15   w.transition(:init, { true => :up, false => :start }) do |on|
16     on.condition(:process_running) do |c|
17       c.running = true
18     end
19   end
20   
21   # determine when process has finished starting
22   w.transition([:start, :restart], :up) do |on|
23     on.condition(:process_running) do |c|
24       c.running = true
25     end
26     
27     # failsafe
28     on.condition(:tries) do |c|
29       c.times = 5
30       c.transition = :start
31     end
32   end
34   # start if process is not running
35   w.transition(:up, :start) do |on|
36     on.condition(:process_exits)
37   end
38   
39   # restart if memory or cpu is too high
40   w.transition(:up, :restart) do |on|
41     on.condition(:memory_usage) do |c|
42       c.interval = 20
43       c.above = 50.megabytes
44       c.times = [3, 5]
45     end
46     
47     on.condition(:cpu_usage) do |c|
48       c.interval = 10
49       c.above = 10.percent
50       c.times = [3, 5]
51     end
52   end
53   
54   # lifecycle
55   w.lifecycle do |on|
56     on.condition(:flapping) do |c|
57       c.to_state = [:start, :restart]
58       c.times = 5
59       c.within = 5.minute
60       c.transition = :unmonitored
61       c.retry_in = 10.minutes
62       c.retry_times = 5
63       c.retry_within = 2.hours
64     end
65   end
66 end