From d9a23580148c4923050852baecbd5b26c70aca5f Mon Sep 17 00:00:00 2001 From: Shayon Mukherjee Date: Wed, 26 Jul 2017 19:45:15 -0700 Subject: [PATCH] Setup signal to trap SIGINT and gracefully stop server This way, when you send `SIGINT` to a running a server, when running via `rails s`, a graceful shutdown/stop will be performed. Before this, not trapping `SIGINT` would mean that either `Rails::Server#start` or `::Rack::Server#start` would be trapping `SIGINT` and exiting the process. --- lib/puma/launcher.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index 48867b2c85..adcdfaa308 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -398,6 +398,20 @@ def setup_signals log "*** SIGTERM not implemented, signal based gracefully stopping unavailable!" end + begin + Signal.trap "SIGINT" do + if Puma.jruby? + @status = :exit + graceful_stop + exit + end + + stop + end + rescue Exception + log "*** SIGINT not implemented, signal based gracefully stopping unavailable!" + end + begin Signal.trap "SIGHUP" do if @runner.redirected_io? @@ -409,14 +423,6 @@ def setup_signals rescue Exception log "*** SIGHUP not implemented, signal based logs reopening unavailable!" end - - if Puma.jruby? - Signal.trap("INT") do - @status = :exit - graceful_stop - exit - end - end end end end