1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Merge pull request #561 from theoldreader/sighup

Implement SIGHUP for logs reopening
This commit is contained in:
Evan Phoenix 2014-08-04 10:13:53 -06:00
commit b657b14872
3 changed files with 27 additions and 2 deletions

View file

@ -38,5 +38,6 @@ Puma cluster responds to these signals:
- `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
- `USR2` restart workers
- `USR1` restart workers in phases, a rolling restart.
- `HUP` reopen log files defined in stdout_redirect configuration parameter
- `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
- `CHLD`

View file

@ -537,6 +537,14 @@ module Puma
log "*** SIGTERM not implemented, signal based gracefully stopping unavailable!"
end
begin
Signal.trap "SIGHUP" do
redirect_io
end
rescue Exception
log "*** SIGHUP not implemented, signal based logs reopening unavailable!"
end
if jruby?
Signal.trap("INT") do
@status = :exit
@ -564,6 +572,10 @@ module Puma
true
end
def redirect_io
@runner.redirect_io
end
def stats
@runner.stats
end

View file

@ -36,6 +36,12 @@ module Puma
end
end
def redirect_io
super
@workers.each { |x| x.hup }
end
class Worker
def initialize(idx, pid, phase)
@index = idx
@ -82,6 +88,11 @@ module Puma
Process.kill "KILL", @pid
rescue Errno::ESRCH
end
def hup
Process.kill "HUP", @pid
rescue Errno::ESRCH
end
end
def spawn_workers
@ -172,6 +183,7 @@ module Puma
$0 = "puma: cluster worker #{index}: #{master}"
Signal.trap "SIGINT", "IGNORE"
@workers = []
@master_read.close
@suicide_pipe.close