public
Description: I eat URLs. RAWRRRRR!
Clone URL: git://github.com/bottlecaplabs/zombieurl.git
Search Repo:
zombieurl / config / zombieurl.god
100644 60 lines (52 sloc) 1.683 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
begin
  require '/etc/email.god'
rescue LoadError
end
 
RAILS_ROOT = "/var/www/apps/zombieurl"
 
# mongrel_rails start -c /var/www/apps/zombieurl -e production -p 3000 -P /var/www/apps/zombieurl/log/mongrel.3000.pid -d
 
%w{3000 3001 3002}.each do |port|
  God.watch do |w|
    w.name = "zombieurl-mongrel-#{port}"
    w.group = 'mongrels'
    w.interval = 30.seconds # default
    w.start = "mongrel_rails start -c #{RAILS_ROOT} -e production -p #{port} \
-P #{RAILS_ROOT}/log/mongrel.#{port}.pid -d"
    w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.#{port}.pid"
    w.restart = "mongrel_rails restart -P #{RAILS_ROOT}/log/mongrel.#{port}.pid"
    w.start_grace = 20.seconds
    w.restart_grace = 20.seconds
    w.pid_file = File.join(RAILS_ROOT, "log/mongrel.#{port}.pid")
    
    w.behavior(:clean_pid_file)
 
    w.start_if do |start|
      start.condition(:process_running) do |c|
        c.running = false
        c.notify = 'reports'
      end
    end
    
    w.restart_if do |restart|
      restart.condition(:memory_usage) do |c|
        c.above = 150.megabytes
        c.times = [3, 5] # 3 out of 5 intervals
        c.notify = 'reports'
      end
    
      restart.condition(:cpu_usage) do |c|
        c.above = 50.percent
        c.times = 5
        c.notify = 'reports'
      end
    end
    
    # lifecycle
    w.lifecycle do |on|
      on.condition(:flapping) do |c|
        c.to_state = [:start, :restart]
        c.times = 5
        c.within = 5.minute
        c.transition = :unmonitored
        c.retry_in = 10.minutes
        c.retry_times = 5
        c.retry_within = 2.hours
        c.notify = 'reports'
      end
    end
  end
end