Skip to content

Commit

Permalink
Setup signal to trap SIGINT and gracefully stop server (#1377)
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
shayonj authored and nateberkopec committed Aug 16, 2017
1 parent aa16777 commit 8903eea
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 8903eea

Please sign in to comment.