fork/exec string command for self-daemonizing process, but wait for process to exit
[god.git] / test / configs / daemon_events / daemon_events.god
blob8ea57d5cd4d9e146c6b3d9f2e59d40ffef587774
1 God.watch do |w|
2   w.name = "daemon-events"
3   w.interval = 5.seconds
4   w.start = '/usr/local/bin/ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' start'
5   w.stop = '/usr/local/bin/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   
9   w.behavior(:clean_pid_file)
10   
11   # determine the state on startup
12   w.transition(:init, { true => :up, false => :start }) do |on|
13     on.condition(:process_running) do |c|
14       c.running = true
15     end
16   end
17   
18   # determine when process has finished starting
19   w.transition([:start, :restart], :up) do |on|
20     on.condition(:process_running) do |c|
21       c.running = true
22     end
23     
24     # failsafe
25     on.condition(:tries) do |c|
26       c.times = 2
27       c.transition = :start
28     end
29   end
31   # start if process is not running
32   w.transition(:up, :start) do |on|
33     on.condition(:process_exits)
34   end
35 end