0
require 'active_support'
0
+require 'action_controller/vendor/rack'
0
+# TODO: Push Thin adapter upstream so we don't need worry about requiring it
0
- require_library_or_gem '
fcgi'
0
+ require_library_or_gem '
thin'
0
- require_library_or_gem 'mongrel'
0
- # Mongrel not available
0
+ :environment => (ENV['RAILS_ENV'] || "development").dup,
0
+ :config => RAILS_ROOT + "/config.ru",
0
+ARGV.clone.options do |opts|
0
+ opts.on("-p", "--port=port", Integer,
0
+ "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
0
+ opts.on("-b", "--binding=ip", String,
0
+ "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
0
+ opts.on("-c", "--config=file", String,
0
+ "Use custom rackup configuration file") { |v| options[:config] = v }
0
+ opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true }
0
+ opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
0
+ opts.on("-e", "--environment=name", String,
0
+ "Specifies the environment to run this server under (test/development/production).",
0
+ "Default: development") { |v| options[:environment] = v }
0
+ opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
0
- require_library_or_gem 'thin'
0
+server = Rack::Handler.get(ARGV.first) rescue nil
0
+ server = Rack::Handler::Mongrel
0
+ server = Rack::Handler::WEBrick
0
-server = case ARGV.first
0
- when "mongrel", "webrick", "thin"
0
+puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
0
+puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}"
0
+%w(cache pids sessions sockets).each do |dir_to_make|
0
+ FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make))
0
+ pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
0
+ File.open(pid, 'w'){ |f| f.write(Process.pid) }
0
+ at_exit { File.delete(pid) if File.exist?(pid) }
0
+ENV["RAILS_ENV"] = options[:environment]
0
+RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
0
+require RAILS_ROOT + "/config/environment"
0
+if File.exist?(options[:config])
0
+ config = options[:config]
0
+ cfgfile = File.read(config)
0
+ if cfgfile[/^#\\(.*)/]
0
+ opts.parse!($1.split(/\s+/))
0
+ app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config)
0
+ app = Object.const_get(File.basename(config, '.rb').capitalize)
0
+ app = Rack::Builder.new {
0
+ use Rails::Rack::Logger
0
+ use Rails::Rack::Static
0
+ run ActionController::Dispatcher.new
0
- puts "=> Booting WEBrick..."
0
- puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)"
0
- puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)"
0
+ require_library_or_gem 'ruby-debug'
0
+ Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
0
+ puts "=> Debugger enabled"
0
+ puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
0
-%w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) }
0
-require "commands/servers/#{server}"
0
+puts "=> Call with -d to detach"
0
+puts "=> Ctrl-C to shutdown server"
0
+ server.run(app, options.merge(:AccessLog => []))
Hell yes.
Thank you for this.
Woohoo! About time!