1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Delay sinatra message until handler has started; Application.run! has optional block to execute once handler is going

This commit is contained in:
David Waite 2011-07-01 00:25:52 -06:00
parent e3854d311f
commit 18eb7ba4d2

View file

@ -1188,16 +1188,20 @@ module Sinatra
end
# Run the Sinatra app as a self-hosted server using
# Thin, Mongrel or WEBrick (in that order)
# Thin, Mongrel or WEBrick (in that order). If given a block, will call
# with the constructed handler once we have taken the stage.
def run!(options={})
set options
handler = detect_rack_handler
handler_name = handler.name.gsub(/.*::/, '')
$stderr.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|
unless handler_name =~ /cgi/i
$stderr.puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " +
"on #{port} for #{environment} with backup from #{handler_name}"
end
[:INT, :TERM].each { |sig| trap(sig) { quit!(server, handler_name) } }
set :running, true
yield handler if block_given?
end
rescue Errno::EADDRINUSE => e
$stderr.puts "== Someone is already performing on port #{port}!"