-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunicorn.rb
38 lines (31 loc) · 1.07 KB
/
unicorn.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# taken from http://blog.railsonfire.com/2012/05/06/Unicorn-on-Heroku.html
worker_processes 3
timeout 120 # 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 we want to move our redis connection out of $redis, drop connection to give new worker a new conection. i.e.:
if defined?(Redis)
Redis.current.quit
$redis.client.disconnect
Rails.logger.info('Disconnected from Redis')
end
sleep 1
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 we want to move our redis connection out of $redis, establish a new connection for the new worker. i.e.:
if defined?(Redis)
$redis = Redis.new(:host => 'localhost', :port => 6379)
$redis.select(1)
Rails.logger.info('Connected to Redis')
end
end