implemented cli control
[god.git] / test / configs / test.rb
blob2a0c36419913339b0b5cf6a5253f38dded1951f0
1 if $0 == __FILE__
2   require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
3 end
5 ENV['GOD_TEST_RAILS_ROOT'] || abort("Set a rails root for testing in an environment variable called GOD_TEST_RAILS_ROOT")
7 RAILS_ROOT = ENV['GOD_TEST_RAILS_ROOT']
9 God.meddle do |god|
10   god.watch do |w|
11     w.name = "local-3000"
12     w.interval = 5 # seconds
13     w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -p 3001 -d"
14     w.restart = "mongrel_rails restart -P ./log/mongrel.pid -c #{RAILS_ROOT}"
15     w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
16     w.restart_grace = 5 # seconds
17     w.stop_grace = 5 # seconds
18     w.autostart = false
19     # w.user = "kev"
20     # w.group = "kev"
21     
22     pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
23     
24     # clean pid files before start if necessary
25     w.behavior(:clean_pid_file) do |b|
26       b.pid_file = pid_file
27     end
28     
29     # determine the state on startup
30     w.transition(:init, { true => :up, false => :start }) 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     # determine when process has finished starting
38     w.transition([:start, :restart], :up) do |on|
39       on.condition(:process_running) do |c|
40         c.running = true
41         c.pid_file = pid_file
42       end
43     end
44   
45     # start if process is not running
46     w.transition(:up, :start) do |on|
47       on.condition(:process_exits) do |c|
48         c.pid_file = pid_file
49       end
50     end
51     
52     # restart if memory or cpu is too high
53     w.transition(:up, :restart) do |on|
54       on.condition(:memory_usage) do |c|
55         c.interval = 20
56         c.pid_file = pid_file
57         c.above = (50 * 1024) # 50mb
58         c.times = [3, 5]
59       end
60       
61       on.condition(:cpu_usage) do |c|
62         c.interval = 10
63         c.pid_file = pid_file
64         c.above = 10 # percent
65         c.times = [3, 5]
66       end
67     end
68   end
69   
70   # clear old session files
71   # god.watch do |w|
72   #   w.name = "local-session-cleanup"
73   #   w.start = lambda do
74   #     Dir["#{RAILS_ROOT}/tmp/sessions/ruby_sess.*"].select do |f|
75   #       File.mtime(f) < Time.now - (7 * 24 * 60 * 60)
76   #     end.each { |f| File.delete(f) }
77   #   end
78   #   
79   #   w.start_if do |start|
80   #     start.condition(:always)
81   #   end
82   # end
83 end