put watch back into previous state after a god load
[god.git] / test / configs / daemon_events / daemon_events.god
blob3a91f980aafe5bff7a8175dc95c7443018fc20a6
1 God.watch do |w|
2   w.name = "daemon-events"
3   w.interval = 5.seconds
4   w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' start'
5   w.stop = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server_stop.rb])
6   w.pid_file = '/var/run/daemon-events.pid'
7   w.log = File.join(File.dirname(__FILE__), 'daemon_events.log')
8   w.uid = 'tom'
9   w.gid = 'tom'
10   
11   w.behavior(:clean_pid_file)
12   
13   # determine the state on startup
14   w.transition(:init, { true => :up, false => :start }) do |on|
15     on.condition(:process_running) do |c|
16       c.running = true
17     end
18   end
19   
20   # determine when process has finished starting
21   w.transition([:start, :restart], :up) do |on|
22     on.condition(:process_running) do |c|
23       c.running = true
24     end
25     
26     # failsafe
27     on.condition(:tries) do |c|
28       c.times = 2
29       c.transition = :start
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 end