Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
unicorn.rb
# config/unicorn.rb
# See comment by @paulelliott
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 29
preload_app true
# Shouldn't need to do anything for redis, since it's already connecting-on-request rather than on boot.
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
# , max_queue_size: 2, on_error: Proc.new { |status, msg| Rails.logger.fatal "analytics: #{msg}" }, batch_size: 1
# defined?(Analytics) && ENV['SEGMENT_IO_SECRET'] && Analytics.init(secret: ENV['SEGMENT_IO_SECRET']) if Feature.metrics?
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.