<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,45 +1,111 @@
 require 'active_support'
 require 'fileutils'
+require 'action_controller/vendor/rack'
+require 'optparse'
 
+# TODO: Push Thin adapter upstream so we don't need worry about requiring it
 begin
-  require_library_or_gem 'fcgi'
+  require_library_or_gem 'thin'
 rescue Exception
-  # FCGI not available
+  # Thin not available
 end
 
-begin
-  require_library_or_gem 'mongrel'
-rescue Exception
-  # Mongrel not available
+options = {
+  :Port        =&gt; 3000,
+  :Host        =&gt; &quot;0.0.0.0&quot;,
+  :environment =&gt; (ENV['RAILS_ENV'] || &quot;development&quot;).dup,
+  :config      =&gt; RAILS_ROOT + &quot;/config.ru&quot;,
+  :detach      =&gt; false,
+  :debugger    =&gt; false
+}
+
+ARGV.clone.options do |opts|
+  opts.on(&quot;-p&quot;, &quot;--port=port&quot;, Integer,
+          &quot;Runs Rails on the specified port.&quot;, &quot;Default: 3000&quot;) { |v| options[:Port] = v }
+  opts.on(&quot;-b&quot;, &quot;--binding=ip&quot;, String,
+          &quot;Binds Rails to the specified ip.&quot;, &quot;Default: 0.0.0.0&quot;) { |v| options[:Host] = v }
+  opts.on(&quot;-c&quot;, &quot;--config=file&quot;, String,
+          &quot;Use custom rackup configuration file&quot;) { |v| options[:config] = v }
+  opts.on(&quot;-d&quot;, &quot;--daemon&quot;, &quot;Make server run as a Daemon.&quot;) { options[:detach] = true }
+  opts.on(&quot;-u&quot;, &quot;--debugger&quot;, &quot;Enable ruby-debugging for the server.&quot;) { options[:debugger] = true }
+  opts.on(&quot;-e&quot;, &quot;--environment=name&quot;, String,
+          &quot;Specifies the environment to run this server under (test/development/production).&quot;,
+          &quot;Default: development&quot;) { |v| options[:environment] = v }
+
+  opts.separator &quot;&quot;
+
+  opts.on(&quot;-h&quot;, &quot;--help&quot;, &quot;Show this help message.&quot;) { puts opts; exit }
+
+  opts.parse!
 end
 
-begin
-  require_library_or_gem 'thin'
-rescue Exception
-  # Thin not available
+server = Rack::Handler.get(ARGV.first) rescue nil
+unless server
+  begin
+    server = Rack::Handler::Mongrel
+  rescue LoadError =&gt; e
+    server = Rack::Handler::WEBrick
+  end
 end
 
-server = case ARGV.first
-  when &quot;mongrel&quot;, &quot;webrick&quot;, &quot;thin&quot;
-    ARGV.shift
-  else
-    if defined?(Mongrel)
-      &quot;mongrel&quot;
-    elsif defined?(Thin)
-      &quot;thin&quot;
-    else
-      &quot;webrick&quot;
+puts &quot;=&gt; Booting #{ActiveSupport::Inflector.demodulize(server)}&quot;
+puts &quot;=&gt; Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}&quot;
+
+%w(cache pids sessions sockets).each do |dir_to_make|
+  FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make))
+end
+
+if options[:detach]
+  Process.daemon
+  pid = &quot;#{RAILS_ROOT}/tmp/pids/server.pid&quot;
+  File.open(pid, 'w'){ |f| f.write(Process.pid) }
+  at_exit { File.delete(pid) if File.exist?(pid) }
+end
+
+ENV[&quot;RAILS_ENV&quot;] = options[:environment]
+RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
+require RAILS_ROOT + &quot;/config/environment&quot;
+
+if File.exist?(options[:config])
+  config = options[:config]
+  if config =~ /\.ru$/
+    cfgfile = File.read(config)
+    if cfgfile[/^#\\(.*)/]
+      opts.parse!($1.split(/\s+/))
     end
+    app = eval(&quot;Rack::Builder.new {( &quot; + cfgfile + &quot;\n )}.to_app&quot;, nil, config)
+  else
+    require config
+    app = Object.const_get(File.basename(config, '.rb').capitalize)
+  end
+else
+  app = Rack::Builder.new {
+    use Rails::Rack::Logger
+    use Rails::Rack::Static
+    run ActionController::Dispatcher.new
+  }.to_app
 end
 
-case server
-  when &quot;webrick&quot;
-    puts &quot;=&gt; Booting WEBrick...&quot;
-  when &quot;mongrel&quot;
-    puts &quot;=&gt; Booting Mongrel (use 'script/server webrick' to force WEBrick)&quot;
-  when &quot;thin&quot;
-    puts &quot;=&gt; Booting Thin (use 'script/server webrick' to force WEBrick)&quot;
+if options[:debugger]
+  begin
+    require_library_or_gem 'ruby-debug'
+    Debugger.start
+    Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
+    puts &quot;=&gt; Debugger enabled&quot;
+  rescue Exception
+    puts &quot;You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'&quot;
+    exit
+  end
 end
 
-%w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) }
-require &quot;commands/servers/#{server}&quot;
+puts &quot;=&gt; Call with -d to detach&quot;
+
+trap(:INT) { exit }
+
+puts &quot;=&gt; Ctrl-C to shutdown server&quot;
+
+begin
+  server.run(app, options.merge(:AccessLog =&gt; []))
+ensure
+  puts 'Exiting'
+end</diff>
      <filename>railties/lib/commands/server.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>railties/lib/commands/servers/base.rb</filename>
    </removed>
    <removed>
      <filename>railties/lib/commands/servers/mongrel.rb</filename>
    </removed>
    <removed>
      <filename>railties/lib/commands/servers/thin.rb</filename>
    </removed>
    <removed>
      <filename>railties/lib/commands/servers/webrick.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>cc67272cba35e50afa73cfec856c1677b204ae7e</id>
    </parent>
  </parents>
  <author>
    <name>Joshua Peek</name>
    <login>josh</login>
    <email>josh@joshpeek.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/708f4c3ae6a41a46ab36a05ea4e126392b81511b</url>
  <id>708f4c3ae6a41a46ab36a05ea4e126392b81511b</id>
  <committed-date>2008-11-22T12:48:32-08:00</committed-date>
  <authored-date>2008-11-22T12:48:32-08:00</authored-date>
  <message>Switch script/server to use rack processor</message>
  <tree>9d2f07ecf9c4bf8b1fbe1a25236a4dea95950ad6</tree>
  <committer>
    <name>Joshua Peek</name>
    <login>josh</login>
    <email>josh@joshpeek.com</email>
  </committer>
</commit>
