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

Implement SIGHUP for logs reopening

This commit is contained in:
Dmitry Krasnoukhov 2014-07-27 17:01:05 +03:00
parent 55b9ce01e5
commit 7c41d0887f
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
@ -104,9 +115,9 @@ module Puma
end
def next_worker_index
all_positions = 0...@options[:workers]
all_positions = 0...@options[:workers]
occupied_positions = @workers.map { |w| w.index }
available_positions = all_positions.to_a - occupied_positions
available_positions = all_positions.to_a - occupied_positions
available_positions.first
end
@ -172,6 +183,7 @@ module Puma
$0 = "puma: cluster worker #{index}: #{master}"
Signal.trap "SIGINT", "IGNORE"
@workers = []
@master_read.close
@suicide_pipe.close