Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.51 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. God.watch do |w|
  2.   w.name = "unicorn"
  3.  
  4.   w.interval = 30.seconds
  5.   w.start_grace = 10.seconds            # Segmentation fault if start_grace/restart_grace are removed
  6.   w.restart_grace = 12.seconds          # Segmentation fault if start_grace/restart_grace are removed
  7.   w.start = "cd /home/deploy/apps/ms/current && RAILS_ENV=production bundle exec unicorn -D -c /home/deploy/apps/ms/current/config/unicorn.rb"
  8.   w.pid_file = "/home/deploy/apps/ms/shared/pids/unicorn.pid"
  9.   w.uid = "deploy"
  10.   w.gid = "deploy"
  11.  
  12.   w.behavior(:clean_pid_file)
  13.  
  14.   w.transition(:init, { true => :up, false => :start }) do |on|
  15.     on.condition(:process_running) do |c|
  16.       c.running = true
  17.     end
  18.   end
  19.  
  20.   w.transition([:start, :restart], :up) do |on|
  21.     on.condition(:process_running) do |c|
  22.       c.running = true
  23.     end
  24.  
  25.     on.condition(:tries) do |c|
  26.       c.times = 5
  27.       c.transition = :start
  28.     end
  29.   end
  30.  
  31.   w.transition(:up, :start) do |on|
  32.     on.condition(:process_exits)
  33.   end
  34.  
  35.   w.transition(:up, :restart) do |on|
  36.     on.condition(:memory_usage) do |c|
  37.       c.interval = 30.seconds
  38.       c.above = 24.megabytes
  39.       c.times = [3,5]
  40.     end
  41.     on.condition(:cpu_usage) do |c|
  42.       c.interval = 30.seconds
  43.       c.above = 8.percent
  44.       c.times = [3,5]
  45.     end
  46.   end
  47.  
  48.   w.lifecycle do |on|
  49.     on.condition(:flapping) do |c|
  50.       c.to_state = [:start, :restart]
  51.       c.times = 5
  52.       c.within = 5.minutes
  53.       c.transition = :unmonitored
  54.       c.retry_in = 10.minutes
  55.       c.retry_times = 5
  56.       c.retry_within = 2.hours
  57.     end
  58.   end
  59. end