trabajo-afectivo/config/unicorn.rb

30 lines
1 KiB
Ruby
Raw Normal View History

# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
2017-01-07 15:32:29 +00:00
worker_processes 4
timeout 30
stderr_path 'log/unicorn_error.log'
stdout_path 'log/unicorn_access.log'
pid 'tmp/pids/unicorn.pid'
2017-01-07 12:07:05 +00:00
2017-01-07 15:32:29 +00:00
before_fork do |server, _worker|
2017-01-07 12:07:05 +00:00
##
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
# immediately start loading up a new version of itself (loaded with a new
# version of our app). When this new Unicorn is completely loaded
# it will begin spawning workers. The first worker spawned will check to
# see if an .oldbin pidfile exists. If so, this means we've just booted up
# a new Unicorn and need to tell the old one that it can now die. To do so
# we send it a QUIT.
#
# Using this method we get 0 downtime deploys.
2017-01-07 16:16:33 +00:00
old_pid = 'tmp/pids/unicorn.pid.oldbin'
2017-01-07 15:32:29 +00:00
if File.exist?(old_pid) && server.pid != old_pid
2017-01-07 12:07:05 +00:00
begin
2017-01-07 15:32:29 +00:00
Process.kill('QUIT', File.read(old_pid).to_i)
2017-01-07 12:07:05 +00:00
rescue Errno::ENOENT, Errno::ESRCH
2017-01-07 15:32:29 +00:00
logger.info 'Unicorn master already killed. Someone else did our job for us.'
2017-01-07 12:07:05 +00:00
end
end
end