Simplified config file (removing meddle construct)
[god.git] / examples / events.god
blobeb6b712cf724c50afbdc80afecc74a1bfabd1479
1 # This example shows how you might keep a local development Rails server up
2 # and running on your Mac.
4 # Run with:
5 # god -c /path/to/events.god
7 RAILS_ROOT = "/Users/tom/dev/helloworld"
9 God.watch do |w|
10   w.name = "local-3000"
11   w.interval = 5 # seconds
12   w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -d"
13   w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
14   w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
15   
16   # clean pid files before start if necessary
17   w.behavior(:clean_pid_file)
18   
19   # determine the state on startup
20   w.transition(:init, { true => :up, false => :start }) do |on|
21     on.condition(:process_running) do |c|
22       c.running = true
23     end
24   end
25   
26   # determine when process has finished starting
27   w.transition([:start, :restart], :up) do |on|
28     on.condition(:process_running) do |c|
29       c.running = true
30     end
31   end
33   # start if process is not running
34   w.transition(:up, :start) do |on|
35     on.condition(:process_exits)
36   end
37   
38   # restart if memory or cpu is too high
39   w.transition(:up, :restart) do |on|
40     on.condition(:memory_usage) do |c|
41       c.interval = 20
42       c.above = (50 * 1024) # 50mb
43       c.times = [3, 5]
44     end
45     
46     on.condition(:cpu_usage) do |c|
47       c.interval = 10
48       c.above = 10 # percent
49       c.times = [3, 5]
50     end
51   end
52 end