Commit 95b7e30e authored by danielgrippi's avatar danielgrippi

preload_app in unicorn

parent ff71bc5a
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment