2 require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
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']
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
22 pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
24 # clean pid files before start if necessary
25 w.behavior(:clean_pid_file) do |b|
29 # determine the state on startup
30 w.transition(:init, { true => :up, false => :start }) do |on|
31 on.condition(:process_running) do |c|
37 # determine when process has finished starting
38 w.transition([:start, :restart], :up) do |on|
39 on.condition(:process_running) do |c|
45 # start if process is not running
46 w.transition(:up, :start) do |on|
47 on.condition(:process_exits) do |c|
52 # restart if memory or cpu is too high
53 w.transition(:up, :restart) do |on|
54 on.condition(:memory_usage) do |c|
57 c.above = (50 * 1024) # 50mb
61 on.condition(:cpu_usage) do |c|
64 c.above = 10 # percent
70 # clear old session files
72 # w.name = "local-session-cleanup"
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) }
79 # w.start_if do |start|
80 # start.condition(:always)