prevent carry-over conditions
[god.git] / ideas / future.god
blob6723030ecde01957db8934a5c401b26f270eff12
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::Contacts::Email.delivery_method = :smtp
10 God::Contacts::Email.server_settings = {}
12 God.contact(:email) do |c|
13   c.name = 'tom'
14   c.email = 'tom@powerset.com'
15   c.group = 'developers'
16   c.throttle = 30.minutes
17 end
19 God.watch do |w|
20   w.name = "local-3000"
21   w.interval = 5.seconds
22   w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -d"
23   w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
24   w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
25   
26   # clean pid files before start if necessary
27   w.behavior(:clean_pid_file)
28   
29   # determine the state on startup
30   w.transition(:init, { true => :up, false => :start }) do |on|
31     on.condition(:process_running) do |c|
32       c.running = true
33     end
34   end
35   
36   # determine when process has finished starting
37   w.transition([:start, :restart], :up) do |on|
38     on.condition(:process_running) do |c|
39       c.running = true
40     end
41   end
43   # start if process is not running
44   w.transition(:up, :start) do |on|
45     on.condition(:process_exits)
46   end
47   
48   # restart if memory or cpu is too high
49   w.transition(:up, :restart) do |on|
50     on.condition(:memory_usage) do |c|
51       c.interval = 20
52       c.above = 50.megabytes
53       c.times = [3, 5]
54     end
55     
56     on.condition(:cpu_usage) do |c|
57       c.interval = 10
58       c.above = 10.percent
59       c.times = [3, 5]
60     end
61   end
62   
63   # lifecycle
64   w.lifecycle do |on|
65     on.condition(:flapping) do |c|
66       c.to_state = [:start, :restart]
67       c.times = 5
68       c.within = 30.seconds
69       c.transition = nil
70       c.retry = 60.seconds
71       c.giveup_tries = 5
72       c.notify = 'tom'
73     end
74     
75     on.condition(:memory_usage) do |c|
76       c.interval = 20
77       c.above = 40.megabytes
78       c.times = [3, 5]
79       c.notify = 'tom'
80     end
81   end
82 end