Skip to content

Instantly share code, notes, and snippets.

@hschoenburg
Created June 23, 2013 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hschoenburg/5846911 to your computer and use it in GitHub Desktop.
Save hschoenburg/5846911 to your computer and use it in GitHub Desktop.
unicorn.rb
# config/unicorn.rb
# See comment by @paulelliott
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 29
preload_app true
# Shouldn't need to do anything for redis, since it's already connecting-on-request rather than on boot.
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
# , max_queue_size: 2, on_error: Proc.new { |status, msg| Rails.logger.fatal "analytics: #{msg}" }, batch_size: 1
# defined?(Analytics) && ENV['SEGMENT_IO_SECRET'] && Analytics.init(secret: ENV['SEGMENT_IO_SECRET']) if Feature.metrics?
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment