Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return proper exit code for TERM signal #1337

Merged
merged 1 commit into from Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/puma/cluster.rb
Expand Up @@ -375,7 +375,10 @@ def setup_signals
log "Early termination of worker"
exit! 0
else
stop_workers
stop

raise SignalException, "SIGTERM"
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/puma/launcher.rb
Expand Up @@ -392,7 +392,9 @@ def setup_signals

begin
Signal.trap "SIGTERM" do
stop
graceful_stop

raise SignalException, "SIGTERM"
end
rescue Exception
log "*** SIGTERM not implemented, signal based gracefully stopping unavailable!"
Expand Down
33 changes: 33 additions & 0 deletions test/test_integration.rb
Expand Up @@ -53,6 +53,21 @@ def server(argv)
@server
end

def start_forked_server(argv)
pid = fork do
exec "#{Gem.ruby} -I lib/ bin/puma -b tcp://127.0.0.1:#{@tcp_port} #{argv}"
end

sleep 5
pid
end

def stop_forked_server(pid)
Process.kill(:TERM, pid)
sleep 1
Process.wait2(pid)
end

def restart_server_and_listen(argv)
skip_on_appveyor
server(argv)
Expand Down Expand Up @@ -218,4 +233,22 @@ def test_restart_restores_environment
assert_includes new_reply, "Hello RAND"
refute_equal initial_reply, new_reply
end

def test_term_signal_exit_code_in_single_mode
skip if Puma.jruby? || Puma.windows?

pid = start_forked_server("test/rackup/hello.ru")
_, status = stop_forked_server(pid)

assert_equal 15, status
end

def test_term_signal_exit_code_in_clustered_mode
skip if Puma.jruby? || Puma.windows?

pid = start_forked_server("-w 2 test/rackup/hello.ru")
_, status = stop_forked_server(pid)

assert_equal 15, status
end
end