81c2394e427ffeecb9bfc16b5d39311f5094c0f3
[god.git] / test / configs / test.rb
blob81c2394e427ffeecb9bfc16b5d39311f5094c0f3
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.init do |g|
10   # g.host = 
11   # g.port = 7777
12   # g.pid_file_directory = 
13 end
15 class SimpleNotifier
16   def self.notify(str)
17     puts "Notifying: #{str}"
18   end
19 end
21 God.watch do |w|
22   w.name = "local-3000"
23   w.interval = 5.seconds
24   w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -p 3001 -d"
25   w.restart = "mongrel_rails restart -P ./log/mongrel.pid -c #{RAILS_ROOT}"
26   w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
27   w.restart_grace = 5.seconds
28   w.stop_grace = 5.seconds
29   w.autostart = true
30   w.uid = 'kev'
31   w.gid = 'kev'
32   w.group = 'mongrels'
33   w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
34   
35   # clean pid files before start if necessary
36   w.behavior(:clean_pid_file)
37   
38   w.behavior(:notify_when_flapping) do |b|
39     b.failures = 5
40     b.seconds = 60.seconds
41     b.notifier = SimpleNotifier
42   end
43   
44   # determine the state on startup
45   w.transition(:init, { true => :up, false => :start }) do |on|
46     on.condition(:process_running) do |c|
47       c.running = true
48     end
49   end
50   
51   # determine when process has finished starting
52   w.transition([:start, :restart], :up) do |on|
53     on.condition(:process_running) do |c|
54       c.running = true
55     end
56   end
58   # start if process is not running
59   w.transition(:up, :start) do |on|
60     on.condition(:process_exits)
61   end
62   
63   # restart if memory or cpu is too high
64   w.transition(:up, :restart) do |on|
65     on.condition(:memory_usage) do |c|
66       c.interval = 1
67       c.above = 50.megabytes
68       c.times = [3, 5]
69     end
70     
71     on.condition(:cpu_usage) do |c|
72       c.interval = 1
73       c.above = 10.percent
74       c.times = [3, 5]
75     end
76   end
77 end