extracted behavior code
[god.git] / test / configs / real.rb
blob09324339671e43d9df6acc11baa7bdfc3d8ba062
1 if $0 == __FILE__
2   require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
3 end
5 RAILS_ROOT = "/Users/tom/dev/gravatar2"
7 God.meddle do |god|
8   god.interval = 5 # seconds
9   
10   god.watch do |w|
11     w.name = "local-3000"
12     w.cwd = RAILS_ROOT
13     w.start = "mongrel_rails start -P ./log/mongrel.pid -d"
14     w.stop = "mongrel_rails stop -P ./log/mongrel.pid"
15     w.grace = 5
16     
17     pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
18     
19     w.behavior(:clean_pid_file) do |b|
20       b.pid_file = pid_file
21     end
22   
23     w.start_if do |start|
24       start.condition(:process_not_running) do |c|
25         c.pid_file = pid_file
26       end
27     end
28     
29     w.restart_if do |restart|
30       restart.condition(:memory_usage) do |c|
31         c.pid_file = pid_file
32         c.above = (50 * 1024) # 50mb
33         c.times = [3, 5]
34       end
35       
36       restart.condition(:cpu_usage) do |c|
37         c.pid_file = pid_file
38         c.above = 10 # percent
39         c.times = [3, 5]
40       end
41     end
42   end
43   
44   god.watch do |w|    
45     w.name = "local-session-cleanup"
46     w.cwd = File.join(RAILS_ROOT, 'tmp/sessions')
47     w.start = lambda do
48       Dir['ruby_sess.*'].select { |f| File.mtime(f) < Time.now - (7 * 24 * 60 * 60) }.each { |f| File.delete(f) }
49     end
50     
51     w.start_if do |start|
52       start.condition(:always)
53     end
54   end
55 end