Skip to content

Instantly share code, notes, and snippets.

@corbanb
Created September 20, 2013 15:37
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 corbanb/6639440 to your computer and use it in GitHub Desktop.
Save corbanb/6639440 to your computer and use it in GitHub Desktop.
Basic Unicorn and heroku config file.
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 4)
timeout 120
preload_app true
listen ENV['PORT'].to_i || 3000, tcp_nopush: false
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
if defined?(Resque)
Resque.redis.quit
end
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
# Reset the object cache store (Dalli)
if Rails.cache.respond_to?(:reset)
Rails.cache.reset
Rails.logger.info('Rails cache has been reset')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment