From eddad58657a5089496c5d57f1dbc62fd118284bf Mon Sep 17 00:00:00 2001 From: Shayon Mukherjee Date: Sun, 18 Jun 2017 19:52:18 -0700 Subject: [PATCH] Return proper exit code for TERM signal Attempt at returning the proper exit code (128+15) when TERM signal is sent to the server, for both single and clustered mode. The changes are achieved by restoring signal from within the trap and accordingly killing the process using TERM event. Note: For clustered mode, now that we restore and return the proper exit code, it means, every worker would also return 143 as exit code for INT (ctrl + c) signal, earlier it was 0. Which I believe is ok, because technically a TERM is being sent to the workers, [here](https://github.com/puma/puma/blob/master/lib/puma/cluster.rb#L56). Happy to update/revert on any concerns :). --- lib/puma/cluster.rb | 3 +++ lib/puma/launcher.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 44cb8b4bd5..cdda76d5e0 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -262,6 +262,9 @@ def worker(index, master) Signal.trap "SIGTERM" do server.stop + + Signal.trap("SIGTERM", "DEFAULT") + Process.kill("TERM", Process.pid) end begin diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index ea1c301e26..1db1196adb 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -392,7 +392,10 @@ def setup_signals begin Signal.trap "SIGTERM" do - stop + graceful_stop + + Signal.trap("SIGTERM", "DEFAULT") + Process.kill("TERM", Process.pid) end rescue Exception log "*** SIGTERM not implemented, signal based gracefully stopping unavailable!"