From 8903eea50a1e113b69c5f5395ed0cbd6add7b577 Mon Sep 17 00:00:00 2001 From: Shayon Mukherjee Date: Wed, 16 Aug 2017 08:22:38 -0700 Subject: [PATCH] Setup signal to trap SIGINT and gracefully stop server (#1377) 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 327d8dd6ab..5ec7bc5308 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