fix sample configs, add announce template
[god.git] / examples / local.god
blob3701a6eec27b5ed23f649996536dc29ffd59144b
1 # This example shows how you might keep a local development Rails server up
2 # and running on your Mac.
4 # Run with:
5 # god start -c /path/to/local.god
7 RAILS_ROOT = "/Users/tom/dev/powerset/querytopia"
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} -d"
14     w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
15     w.grace = 5
16     
17     pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
18     
19     # clean pid files before start if necessary
20     w.behavior(:clean_pid_file) do |b|
21       b.pid_file = pid_file
22     end
23   
24     # start if process is not running
25     w.start_if do |start|
26       start.condition(:process_not_running) do |c|
27         c.pid_file = pid_file
28       end
29     end
30     
31     # restart if memory or cpu is too high
32     w.restart_if do |restart|
33       restart.condition(:memory_usage) do |c|
34         c.pid_file = pid_file
35         c.above = (50 * 1024) # 50mb
36         c.times = [3, 5]
37       end
38       
39       restart.condition(:cpu_usage) do |c|
40         c.pid_file = pid_file
41         c.above = 10 # percent
42         c.times = [3, 5]
43       end
44     end
45   end
46   
47   # clear old session files
48   god.watch do |w|    
49     w.name = "local-session-cleanup"
50     w.interval = 60 # seconds
51     w.cwd = File.join(RAILS_ROOT, 'tmp/sessions')
52     w.start = lambda do
53       Dir['ruby_sess.*'].select { |f| File.mtime(f) < Time.now - (7 * 24 * 60 * 60) }.each { |f| File.delete(f) }
54     end
55     
56     w.start_if do |start|
57       start.condition(:always)
58     end
59   end
60 end