diff --git a/config/unicorn.rb b/config/unicorn.rb index 6cfcc8f6d..7d943d226 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -7,7 +7,7 @@ rails_env = ENV['RAILS_ENV'] || 'development' worker_processes 1 ## Load the app before spawning workers -#preload_app true +preload_app true # How long to wait before killing an unresponsive worker timeout 30 @@ -23,7 +23,12 @@ end before_fork do |server, worker| # If using preload_app, enable this line - #ActiveRecord::Base.disconnect! + ActiveRecord::Base.connection.disconnect! + + # disconnect redis if in use + if !AppConfig.single_process_mode? + Resque.redis.client.disconnect + end old_pid = '/var/run/diaspora/diaspora.pid.oldbin' if File.exists?(old_pid) && server.pid != old_pid @@ -38,7 +43,17 @@ end after_fork do |server, worker| # If using preload_app, enable this line - # ActiveRecord::Base.establish_connection + ActiveRecord::Base.establish_connection + + # copy pasta from resque.rb because i'm a bad person + if !AppConfig.single_process_mode? + if redis_to_go = ENV["REDISTOGO_URL"] + uri = URI.parse(redis_to_go) + Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) + elsif AppConfig[:redis_url] + Resque.redis = Redis.new(:host => AppConfig[:redis_url], :port => 6379) + end + end # Enable this line to have the workers run as different user/group #worker.user(user, group)