Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
our unicorn config
rails_env = ENV['RAILS_ENV'] || 'production'
preload_app true
# number of workers - makes sure this matches memory config
worker_processes Integer(ENV['UNICORN_WORKERS'] || 2)
# restart workers if request takes too long
timeout Integer(ENV['UNICORN_TIMEOUT'] || 25)
# Only allow reasonable backlog of requests per worker
# Force load balancer to send requests elsewhere if backlogged
listen ENV['PORT'], :backlog => Integer(ENV['UNICORN_BACKLOG'] || 200)
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT',
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection_handler.clear_all_connections!'Disconnected from ActiveRecord')
sleep 1
after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection_handler.verify_active_connections!'Connected to ActiveRecord')
# When in Unicorn, this block needs to go in unicorn's `after_fork` callback:
Sidekiq.configure_client do |config|
config.redis = { :url => ENV['REDIS_URL'],
:namespace => 'nnnnnnnnnnnn' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment