Skip to content

Commit

Permalink
Setup signal to trap SIGINT and gracefully stop server
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Shayon Mukherjee committed Aug 5, 2017
1 parent 0d7a8bb commit d9a2358
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/puma/launcher.rb
Expand Up @@ -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?
Expand All @@ -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

0 comments on commit d9a2358

Please sign in to comment.