Skip to content

Instantly share code, notes, and snippets.

@tibbon
Created January 1, 2013 16:25
Show Gist options
  • Select an option

  • Save tibbon/4428394 to your computer and use it in GitHub Desktop.

Select an option

Save tibbon/4428394 to your computer and use it in GitHub Desktop.
My Unicorn config file. Having crashy EOF issues with Postgres with workers.
# What the timeout for killing busy workers is, in seconds
timeout 60
# Whether the app should be pre-loaded
preload_app true
# How many worker processes
worker_processes 3
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|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
if defined?(Resque)
Resque.redis = ENV['REDIS_URI']
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