mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
systemd - fix event firing (#2591)
* systemd - fix event firing * Update test_integration_systemd.rb Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
This commit is contained in:
parent
2654f02acc
commit
f7a2d4eedc
2 changed files with 44 additions and 13 deletions
|
@ -43,6 +43,7 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_phased_restart
|
def start_phased_restart
|
||||||
|
@events.fire_on_restart!
|
||||||
@phase += 1
|
@phase += 1
|
||||||
log "- Starting phased worker restart, phase: #{@phase}"
|
log "- Starting phased worker restart, phase: #{@phase}"
|
||||||
|
|
||||||
|
@ -317,7 +318,7 @@ module Puma
|
||||||
|
|
||||||
stop_workers
|
stop_workers
|
||||||
stop
|
stop
|
||||||
|
@events.fire_on_stopped!
|
||||||
raise(SignalException, "SIGTERM") if @options[:raise_exception_on_sigterm]
|
raise(SignalException, "SIGTERM") if @options[:raise_exception_on_sigterm]
|
||||||
exit 0 # Clean exit, workers were stopped
|
exit 0 # Clean exit, workers were stopped
|
||||||
end
|
end
|
||||||
|
@ -411,12 +412,16 @@ module Puma
|
||||||
|
|
||||||
begin
|
begin
|
||||||
booted = false
|
booted = false
|
||||||
|
in_phased_restart = false
|
||||||
|
workers_not_booted = @options[:workers]
|
||||||
|
|
||||||
while @status == :run
|
while @status == :run
|
||||||
begin
|
begin
|
||||||
if @phased_restart
|
if @phased_restart
|
||||||
start_phased_restart
|
start_phased_restart
|
||||||
@phased_restart = false
|
@phased_restart = false
|
||||||
|
in_phased_restart = true
|
||||||
|
workers_not_booted = @options[:workers]
|
||||||
end
|
end
|
||||||
|
|
||||||
check_workers
|
check_workers
|
||||||
|
@ -444,6 +449,7 @@ module Puma
|
||||||
w.boot!
|
w.boot!
|
||||||
log "- Worker #{w.index} (PID: #{pid}) booted in #{w.uptime.round(2)}s, phase: #{w.phase}"
|
log "- Worker #{w.index} (PID: #{pid}) booted in #{w.uptime.round(2)}s, phase: #{w.phase}"
|
||||||
@next_check = Time.now
|
@next_check = Time.now
|
||||||
|
workers_not_booted -= 1
|
||||||
when "e"
|
when "e"
|
||||||
# external term, see worker method, Signal.trap "SIGTERM"
|
# external term, see worker method, Signal.trap "SIGTERM"
|
||||||
w.instance_variable_set :@term, true
|
w.instance_variable_set :@term, true
|
||||||
|
@ -461,6 +467,10 @@ module Puma
|
||||||
log "! Out-of-sync worker list, no #{pid} worker"
|
log "! Out-of-sync worker list, no #{pid} worker"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if in_phased_restart && workers_not_booted.zero?
|
||||||
|
@events.fire_on_booted!
|
||||||
|
in_phased_restart = false
|
||||||
|
end
|
||||||
|
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
@status = :stop
|
@status = :stop
|
||||||
|
|
|
@ -31,21 +31,18 @@ class TestIntegrationSystemd < TestIntegration
|
||||||
ENV["WATCHDOG_USEC"] = nil
|
ENV["WATCHDOG_USEC"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def socket_message
|
def test_systemd_notify_usr1_phased_restart_cluster
|
||||||
@socket.recvfrom(15)[0]
|
skip_unless :fork
|
||||||
|
assert_restarts_with_systemd :USR1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_systemd_integration
|
def test_systemd_notify_usr2_hot_restart_cluster
|
||||||
cli_server "test/rackup/hello.ru"
|
skip_unless :fork
|
||||||
assert_equal(socket_message, "READY=1")
|
assert_restarts_with_systemd :USR2
|
||||||
|
end
|
||||||
|
|
||||||
connection = connect
|
def test_systemd_notify_usr2_hot_restart_single
|
||||||
restart_server connection
|
assert_restarts_with_systemd :USR2, workers: 0
|
||||||
assert_equal(socket_message, "RELOADING=1")
|
|
||||||
assert_equal(socket_message, "READY=1")
|
|
||||||
|
|
||||||
stop_server
|
|
||||||
assert_equal(socket_message, "STOPPING=1")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_systemd_watchdog
|
def test_systemd_watchdog
|
||||||
|
@ -59,4 +56,28 @@ class TestIntegrationSystemd < TestIntegration
|
||||||
stop_server
|
stop_server
|
||||||
assert_match(socket_message, "STOPPING=1")
|
assert_match(socket_message, "STOPPING=1")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def assert_restarts_with_systemd(signal, workers: 2)
|
||||||
|
cli_server "-w#{workers} test/rackup/hello.ru"
|
||||||
|
assert_equal socket_message, 'READY=1'
|
||||||
|
|
||||||
|
Process.kill signal, @pid
|
||||||
|
connect.write "GET / HTTP/1.1\r\n\r\n"
|
||||||
|
assert_equal socket_message, 'RELOADING=1'
|
||||||
|
assert_equal socket_message, 'READY=1'
|
||||||
|
|
||||||
|
Process.kill signal, @pid
|
||||||
|
connect.write "GET / HTTP/1.1\r\n\r\n"
|
||||||
|
assert_equal socket_message, 'RELOADING=1'
|
||||||
|
assert_equal socket_message, 'READY=1'
|
||||||
|
|
||||||
|
stop_server
|
||||||
|
assert_equal socket_message, 'STOPPING=1'
|
||||||
|
end
|
||||||
|
|
||||||
|
def socket_message
|
||||||
|
@socket.recvfrom(15)[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue