Created
March 11, 2009 17:23
-
-
Save retro/77587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < Sinatra::Base | |
@@server_instance = nil | |
def self.run!(options={}) | |
set options | |
handler = detect_rack_handler | |
handler_name = handler.name.gsub(/.*::/, '') | |
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 => host, :Port => port do |server| | |
@@server_instance = 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 | |
end | |
rescue Errno::EADDRINUSE => e | |
puts "== Someone is already performing on port #{port}!" | |
end | |
def self.kill | |
@@server_instance.respond_to?(:stop!) ? @@server_instance.stop! : @@server_instance.stop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment