forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunicorn.rb
27 lines (25 loc) · 986 Bytes
/
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
worker_processes 4
timeout 30
stderr_path 'log/unicorn_error.log'
stdout_path 'log/unicorn_access.log'
pid 'tmp/pids/unicorn.pid'
before_fork do |server, _worker|
##
# 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.
old_pid = 'tmp/pids/unicorn.pid.oldbin'
if File.exist?(old_pid) && server.pid != old_pid
begin
Process.kill('QUIT', File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
logger.info 'Unicorn master already killed. Someone else did our job for us.'
end
end
end