Skip to content

Commit

Permalink
handle both INT and TERM signals
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Collison authored and rtomayko committed Apr 2, 2010
1 parent 794437e commit 7ee40c6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,12 @@ def use(middleware, *args, &block)
@prototype = nil
@middleware << [middleware, args, block]
end

def quit!(server, handler_name)
## Use thins' hard #stop! if available, otherwise just #stop
server.respond_to?(:stop!) ? server.stop! : server.stop
puts "\n== Sinatra has ended his set (crowd applauds)" unless handler_name =~/cgi/i
end

# Run the Sinatra app as a self-hosted server using
# Thin, Mongrel or WEBrick (in that order)
Expand All @@ -944,11 +950,7 @@ def run!(options={})
puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " +
"on #{port} for #{environment} with backup from #{handler_name}" unless handler_name =~/cgi/i
handler.run self, :Host => bind, :Port => port do |server|
trap(:INT) do
## Use thins' hard #stop! if available, otherwise just #stop
server.respond_to?(:stop!) ? server.stop! : server.stop
puts "\n== Sinatra has ended his set (crowd applauds)" unless handler_name =~/cgi/i
end
[:INT, :TERM].each { |sig| trap(sig) { quit!(server, handler_name) } }
set :running, true
end
rescue Errno::EADDRINUSE => e
Expand Down

0 comments on commit 7ee40c6

Please sign in to comment.