From 576bea6a7cd1dda2221180c19682870856609d9c Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Wed, 11 Apr 2012 11:08:46 -0700 Subject: [PATCH] Shutdown gracefull on SIGTERM. Fixes #53 --- lib/puma/cli.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/puma/cli.rb b/lib/puma/cli.rb index 5586bae3..e588e015 100644 --- a/lib/puma/cli.rb +++ b/lib/puma/cli.rb @@ -266,6 +266,12 @@ module Puma @temp_status_path = @options[:control_path_temp] end + def graceful_stop(server) + log " - Gracefully stopping, waiting for requests to finish" + server.stop(true) + log " - Goodbye!" + end + # Parse the options, load the rackup, start the server and wait # for it to finish. # @@ -412,14 +418,16 @@ module Puma server.begin_restart end + Signal.trap "SIGTERM" do + graceful_stop server + end + log "Use Ctrl-C to stop" begin server.run.join rescue Interrupt - log " - Gracefully stopping, waiting for requests to finish" - server.stop(true) - log " - Goodbye!" + graceful_stop server end File.unlink @temp_status_path if @temp_status_path