Permalink
Browse files

pick a server, any server!

  • Loading branch information...
1 parent 39cee5c commit f747bfe403bcc964cd32157c9563aad93a73f325 @bmizerany bmizerany committed Apr 14, 2008
Showing with 25 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +24 −3 lib/sinatra.rb
View
@@ -2,3 +2,4 @@ doc
pkg
*.log
.DS_Store
+rack*
View
@@ -120,12 +120,32 @@ def build_application
app
end
+ def server
+ @server ||= case options.server
+ when "mongrel"
+ Rack::Handler::Mongrel
+ when "webrick"
+ Rack::Handler::WEBrick
+ when "cgi"
+ Rack::Handler::CGI
+ when "fastcgi"
+ Rack::Handler::FastCGI
+ else
+ if defined?(Rack::Handler::Thin)
+ Rack::Handler::Thin
+ else
+ options.server ||= "mongrel"
+ eval("Rack::Handler::#{options.server.capitalize}")
+ end
+ end
+ end
+
def run
begin
- puts "== Sinatra has taken the stage on port #{port} for #{env}"
+ puts "== Sinatra has taken the stage on port #{port} for #{env} with backup by #{server.name}"
require 'pp'
- Rack::Handler::Mongrel.run(build_application, :Port => port) do |server|
+ server.run(build_application, :Port => port) do |server|
trap(:INT) do
server.stop
puts "\n== Sinatra has ended his set (crowd applauds)"
@@ -722,7 +742,8 @@ def load_options!
OptionParser.new do |op|
op.on('-p port') { |port| default_options[:port] = port }
op.on('-e env') { |env| default_options[:env] = env }
- op.on('-x') { |env| default_options[:mutex] = true }
+ op.on('-x') { default_options[:mutex] = true }
+ op.on('-s server') { |server| default_options[:server] = server }
end.parse!(ARGV.dup.select { |o| o !~ /--name/ })
end

0 comments on commit f747bfe

Please sign in to comment.