From 0507d348a8f233cf16af3773a789f3f836a4cf38 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index ea1c301e26..73129fca40 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -398,6 +398,14 @@ def setup_signals log "*** SIGTERM not implemented, signal based gracefully stopping unavailable!" end + begin + Signal.trap "SIGINT" do + stop + end + rescue Exception + log "*** SIGINT not implemented, signal based gracefully stopping unavailable!" + end + begin Signal.trap "SIGHUP" do if @runner.redirected_io?