finshed and tested event handling; site doc update for v 0.2.0
[god.git] / test / configs / test.rb
blob30f2e2cb7778afb8ba235a0b6238e813c1298069
1 if $0 == __FILE__
2   require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
3 end
5 RAILS_ROOT = "/Users/tom/dev/powerset/speechverb"
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     
14     pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
15     
16     # clean pid files before start if necessary
17     w.behavior(:clean_pid_file) do |b|
18       b.pid_file = pid_file
19     end
20     
21     # determine the state on startup
22     w.transition(:init, { true => :up, false => :start }) do |on|
23       on.condition(:process_running) do |c|
24         c.running = true
25         c.pid_file = pid_file
26       end
27     end
28     
29     # determine when process has finished starting
30     w.transition([:start, :restart], :up) do |on|
31       on.condition(:process_running) do |c|
32         c.running = true
33         c.pid_file = pid_file
34       end
35     end
36   
37     # start if process is not running
38     w.transition(:up, :start) do |on|
39       on.condition(:process_exits) do |c|
40         c.pid_file = pid_file
41       end
42     end
43     
44     # restart if memory or cpu is too high
45     w.transition(:up, :restart) do |on|
46       on.condition(:memory_usage) do |c|
47         c.interval = 20
48         c.pid_file = pid_file
49         c.above = (50 * 1024) # 50mb
50         c.times = [3, 5]
51       end
52       
53       on.condition(:cpu_usage) do |c|
54         c.interval = 10
55         c.pid_file = pid_file
56         c.above = 10 # percent
57         c.times = [3, 5]
58       end
59     end
60   end
61   
62   # clear old session files
63   # god.watch do |w|
64   #   w.name = "local-session-cleanup"
65   #   w.start = lambda do
66   #     Dir["#{RAILS_ROOT}/tmp/sessions/ruby_sess.*"].select do |f|
67   #       File.mtime(f) < Time.now - (7 * 24 * 60 * 60)
68   #     end.each { |f| File.delete(f) }
69   #   end
70   #   
71   #   w.start_if do |start|
72   #     start.condition(:always)
73   #   end
74   # end
75 end