Skip to content

Commit

Permalink
Return proper exit code for TERM signal
Browse files Browse the repository at this point in the history
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 :).
  • Loading branch information
Shayon Mukherjee committed Jun 19, 2017
1 parent 63f3c51 commit 3fa684d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/puma/cluster.rb
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/puma/launcher.rb
Expand Up @@ -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!"
Expand Down

0 comments on commit 3fa684d

Please sign in to comment.