-
-
Save pjkelly/1122cc189c7525a8bb2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dotenv' | |
Dotenv.load | |
listen ENV.fetch('UNICORN_PORT', 5000), :backlog => ENV.fetch('UNICORN_BACKLOG', 200).to_i | |
worker_processes ENV.fetch('UNICORN_CONCURRENCY', 3).to_i | |
timeout ENV.fetch('UNICORN_TIMEOUT', 15).to_i | |
preload_app true | |
if ENV.include?('UNICORN_LOG') | |
stderr_path ENV.fetch('UNICORN_LOG') | |
stdout_path ENV.fetch('UNICORN_LOG') | |
end | |
pid ENV.fetch('UNICORN_PID') if ENV.include?('UNICORN_PID') | |
before_fork do |server, worker| | |
if ENV.include?('UNICORN_PID') | |
f = File.open("#{server.config[:pid]}.lock", 'w') | |
exit unless f.flock(File::LOCK_SH) | |
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| | |
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