Add autostart attribute to prevent processses from starting on god init. Closes PLATF...
[god.git] / test / configs / test.rb
blob33d4a408c551665c13591a0f3a7610ca5acbd3d1
1 if $0 == __FILE__
2   require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
3 end
5 RAILS_ROOT = "/Users/tom/dev/git/helloworld"
7 God.meddle do |god|
8   god.watch do |w|
9     w.name = "local-3000"
10     w.interval = 5 # seconds
11     w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -p 3001 -d"
12     w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
13     # w.autostart = false
14     # w.user = "kev"
15     # w.group = "kev"
16     
17     pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
18     
19     # clean pid files before start if necessary
20     w.behavior(:clean_pid_file) do |b|
21       b.pid_file = pid_file
22     end
23     
24     # determine the state on startup
25     w.transition(:init, { true => :up, false => :start }) do |on|
26       on.condition(:process_running) do |c|
27         c.running = true
28         c.pid_file = pid_file
29       end
30     end
31     
32     # determine when process has finished starting
33     w.transition([:start, :restart], :up) do |on|
34       on.condition(:process_running) do |c|
35         c.running = true
36         c.pid_file = pid_file
37       end
38     end
39   
40     # start if process is not running
41     w.transition(:up, :start) do |on|
42       on.condition(:process_exits) do |c|
43         c.pid_file = pid_file
44       end
45     end
46     
47     # restart if memory or cpu is too high
48     w.transition(:up, :restart) do |on|
49       on.condition(:memory_usage) do |c|
50         c.interval = 20
51         c.pid_file = pid_file
52         c.above = (50 * 1024) # 50mb
53         c.times = [3, 5]
54       end
55       
56       on.condition(:cpu_usage) do |c|
57         c.interval = 10
58         c.pid_file = pid_file
59         c.above = 10 # percent
60         c.times = [3, 5]
61       end
62     end
63   end
64   
65   # clear old session files
66   # god.watch do |w|
67   #   w.name = "local-session-cleanup"
68   #   w.start = lambda do
69   #     Dir["#{RAILS_ROOT}/tmp/sessions/ruby_sess.*"].select do |f|
70   #       File.mtime(f) < Time.now - (7 * 24 * 60 * 60)
71   #     end.each { |f| File.delete(f) }
72   #   end
73   #   
74   #   w.start_if do |start|
75   #     start.condition(:always)
76   #   end
77   # end
78 end