-
-
Save leshill/1401792 to your computer and use it in GitHub Desktop.
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb |
# config/unicorn.rb | |
# See comment by @paulelliott | |
worker_processes 3 | |
timeout 30 | |
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 | |
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_URI'] | |
Rails.logger.info('Connected to Redis') | |
end | |
end |
@premjg, you can find the same documentation for Mongoid 2.x, here : http://two.mongoid.org/docs/rails/railties.html
What would it look like if you were using Mongo, Postgres/ActiveRecord AND Resque? I'm having weird EOF issues with Resque/Postgres and Heroku, and I'm wondering if my config here is part of the issue.
@leshill, there is a comment # If you are using Redis but not Resque, change this
, what should it be changed to if you are just using Redis?
My thought was it would look something like the below text. However, the Redis.current.quit
throws errors because .current
tries to connect to the default localhost (which doesn't exist if using an external Redis server).
before_fork do |server, worker|
if defined?(Redis)
# this throws errors
# Redis.current tries to connect localhost
Redis.current.quit
end
end
after_fork do |server, worker|
if defined?(Redis)
Redis.current = Redis.new(url: ENV['REDIS_URI'])
end
end
@harlow Did you figure the Redis config out. Im using Redistogo without Resque and can't find much in the way of configs like that.
@walidhalabi, Is this true for Mongoid 2.x as well? I couldn't find any supporting documentation. Thanks.