Skip to content

Instantly share code, notes, and snippets.

@flomotlik
Created May 6, 2012 09:03
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 flomotlik/2621160 to your computer and use it in GitHub Desktop.
Save flomotlik/2621160 to your computer and use it in GitHub Desktop.
Unicorn config
#Base on https://gist.github.com/1401792
worker_processes 4 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
preload_app true
before_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
# If you are using Redis but not Resque, change this
if defined?(Resque)
Resque.redis.quit
Rails.logger.info('Disconnected from Redis')
end
sleep 1
end
after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
# If you are using Redis but not Resque, change this
if defined?(Resque)
Resque.redis = ENV['REDIS_URL']
Rails.logger.info('Connected to Redis')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment