Permalink
Browse files

preload_app in unicorn

  • Loading branch information...
1 parent ff71bc5 commit 95b7e30e009a495e15cf54d1e83e8f1ce5c0222f @danielgrippi danielgrippi committed Jan 27, 2012
Showing with 18 additions and 3 deletions.
  1. +18 −3 config/unicorn.rb
View
@@ -7,7 +7,7 @@
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 @@
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 @@
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)

0 comments on commit 95b7e30

Please sign in to comment.