Skip to content

Instantly share code, notes, and snippets.

@bopm
Created April 5, 2012 12:54
Show Gist options
  • Save bopm/2310859 to your computer and use it in GitHub Desktop.
Save bopm/2310859 to your computer and use it in GitHub Desktop.
bluepill unicorn pill
# http://devmull.net/articles/unicorn-resque-bluepill
# http://www.jamievandyke.com/want-some-campfire-with-that-bluepill
app_name = 'rails'
app_env = 'production'
Bluepill.application(app_name) do |app|
RAILS_ROOT = "/var/www/#{app_name}/"
app.uid = app.gid = "www-rails"
app.working_dir = RAILS_ROOT
worker_queues = %w[queue]
app.process("unicorn") do |process|
process.supplementary_groups = ['rvm']
process.pid_file = File.join(RAILS_ROOT, 'tmp', 'pids', 'unicorn.pid')
process.start_command = "bundle exec unicorn_rails -D -c #{app.working_dir}config/unicorn.rb -E #{app_env}"
process.stop_command = "kill -QUIT {{PID}}"
process.restart_command = "kill -USR2 {{PID}}"
process.start_grace_time = 10.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 10.seconds
process.monitor_children do |child_process|
child_process.stop_command = "kill -QUIT {{PID}}"
child_process.checks :mem_usage, :every => 10.seconds, :below => 150.megabytes, :times => [3,4], :fires => :stop
child_process.checks :cpu_usage, :every => 10.seconds, :below => 20, :times => [3,4], :fires => :stop
child_process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
end
end
if defined?(worker_queues)
worker_queues.each_with_index do |queue, i|
app.process("resque-#{i}") do |process|
process.supplementary_groups = ['rvm']
process.group = "resque"
process.pid_file = "#{RAILS_ROOT}/tmp/pids/resque-#{i}.pid"
process.stdout = process.stderr = "#{RAILS_ROOT}/log/resque-#{i}.log"
process.environment = {
'RAILS_ENV' => app_env,
'QUEUE' => queue
}
process.start_command = "bundle exec rake resque:work"
process.stop_command = "kill -QUIT {{PID}}"
process.daemonize = true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment