/
unicorn.rb
46 lines (38 loc) · 1.54 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
39
40
41
42
43
44
45
46
# config/unicorn.rb
ENV["RAILS_ENV"] ||= "development"
worker_processes Integer(ENV["UNICORN_WORKERS"] || 3)
timeout Integer(ENV["UNICORN_TIMEOUT"] || 30)
preload_app true
listen "/tmp/unicorn.reader.sock", :backlog => 64
pid "/tmp/unicorn.reader.pid"
# Production specific settings
if ENV["RAILS_ENV"] == "production"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/home/charlie/apps/reader/current"
# feel free to point this anywhere accessible on the filesystem
user 'charlie', 'staff'
shared_path = "/home/charlie/apps/reader/shared"
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"
end
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
if defined?(Sidekiq)
Sidekiq.configure_client do |config|
rails_root = Rails.root || File.join(File.dirname(__FILE__), "..", "..")
redis_config = YAML.load_file(File.join(rails_root, "config", "redis.yml")
config.redis = { url: redis_config[ENV["RAILS_ENV"]], namespace: 'reader', size: 1 }
end
end
end