public
Created

our unicorn config

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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', Process.pid
end
 
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection_handler.clear_all_connections!
Rails.logger.info('Disconnected from ActiveRecord')
end
sleep 1
end
 
after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection_handler.verify_active_connections!
Rails.logger.info('Connected to ActiveRecord')
end
# 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' }
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.