2 require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
5 RAILS_ROOT = "/Users/tom/dev/git/helloworld"
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}"
17 pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
19 # clean pid files before start if necessary
20 w.behavior(:clean_pid_file) do |b|
24 # determine the state on startup
25 w.transition(:init, { true => :up, false => :start }) do |on|
26 on.condition(:process_running) do |c|
32 # determine when process has finished starting
33 w.transition([:start, :restart], :up) do |on|
34 on.condition(:process_running) do |c|
40 # start if process is not running
41 w.transition(:up, :start) do |on|
42 on.condition(:process_exits) do |c|
47 # restart if memory or cpu is too high
48 w.transition(:up, :restart) do |on|
49 on.condition(:memory_usage) do |c|
52 c.above = (50 * 1024) # 50mb
56 on.condition(:cpu_usage) do |c|
59 c.above = 10 # percent
65 # clear old session files
67 # w.name = "local-session-cleanup"
69 # Dir["#{RAILS_ROOT}/tmp/sessions/ruby_sess.*"].select do |f|
70 # File.mtime(f) < Time.now - (7 * 24 * 60 * 60)
71 # end.each { |f| File.delete(f) }
74 # w.start_if do |start|
75 # start.condition(:always)