Skip to content

Instantly share code, notes, and snippets.

@cs3b
Created August 5, 2010 18:47
Show Gist options
  • Save cs3b/510178 to your computer and use it in GitHub Desktop.
Save cs3b/510178 to your computer and use it in GitHub Desktop.
rails_root = '/home/services/redmine'
rails_env = 'production'
unicorn_pid = '/home/services/redmine/tmp/pids/unicorn.pid'
group = user = 'services'
gemset = 'redmine'
God.watch do |w|
w.name = "redmine_unicorn"
w.group = "services"
w.interval = 30.seconds
w.dir = rails_root
w.env = { 'RAILS_ROOT' => rails_root,
'RAILS_ENV' => "production",
'PATH' => "/home/mj/.rvm/bin:/home/mj/.rvm/gems/ree-1.8.7-2010.02@#{gemset}/bin:/home/mj/.rvm/gems/ree-1.8.7-2010.02@global/bin:/home/services/.rvm/rubies/ree-1.8.7-2010.02/bin:/home/services/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games",
'GEM_HOME' => "/home/mj/.rvm/gems/ree-1.8.7-2010.02@#{gemset}",
'GEM_PATH' => "/home/mj/.rvm/gems/ree-1.8.7-2010.02@#{gemset}:/home/services/.rvm/gems/ree-1.8.7-2010.02@global",
'BUNDLE_PATH' => "/home/mj/.rvm/gems/ree-1.8.7-2010.02@#{gemset}",
'MY_RUBY_HOME' => '/home/mj/.rvm/rubies/ree-1.8.7-2010.02' }
w.start = "/home/mj/.rvm/gems/ree-1.8.7-2010.02@#{gemset}/bin/unicorn_rails -p 10110 -D"
# QUIT gracefully shuts down workers
w.stop = "kill -QUIT `cat #{unicorn_pid}`"
# USR2 causes the master to re-create itself and spawn a new worker pool
# w.restart = "kill -HUP `cat #{unicorn_pid}`"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
w.pid_file = unicorn_pid
w.uid = user
w.gid = group
w.behavior(:clean_pid_file)
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
end
end
w.restart_if do |restart|
restart.condition(:memory_usage) do |c|
c.above = 200.megabytes
c.times = [3, 5] # 3 out of 5 intervals
end
restart.condition(:cpu_usage) do |c|
c.above = 50.percent
c.times = 5
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
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment