aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/commands/server.rb')
-rw-r--r--railties/lib/commands/server.rb75
1 files changed, 19 insertions, 56 deletions
diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb
index db8e8b3d93..64e5b1fa7a 100644
--- a/railties/lib/commands/server.rb
+++ b/railties/lib/commands/server.rb
@@ -1,59 +1,22 @@
-require 'webrick'
-require 'optparse'
-
-OPTIONS = {
- :port => 3000,
- :ip => "0.0.0.0",
- :environment => (ENV['RAILS_ENV'] || "development").dup,
- :server_root => File.expand_path(RAILS_ROOT + "/public/"),
- :server_type => WEBrick::SimpleServer,
- :charset => "UTF-8",
- :mime_types => WEBrick::HTTPUtils::DefaultMimeTypes
-}
-
-ARGV.options do |opts|
- script_name = File.basename($0)
- opts.banner = "Usage: ruby #{script_name} [options]"
-
- opts.separator ""
-
- opts.on("-p", "--port=port", Integer,
- "Runs Rails on the specified port.",
- "Default: 3000") { |OPTIONS[:port]| }
- opts.on("-b", "--binding=ip", String,
- "Binds Rails to the specified ip.",
- "Default: 0.0.0.0") { |OPTIONS[:ip]| }
- opts.on("-e", "--environment=name", String,
- "Specifies the environment to run this server under (test/development/production).",
- "Default: development") { |OPTIONS[:environment]| }
- opts.on("-m", "--mime-types=filename", String,
- "Specifies an Apache style mime.types configuration file to be used for mime types",
- "Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
-
- opts.on("-d", "--daemon",
- "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
- ) { OPTIONS[:server_type] = WEBrick::Daemon }
-
- opts.on("-c", "--charset=charset", String,
- "Set default charset for output.",
- "Default: UTF-8") { |OPTIONS[:charset]| }
-
- opts.separator ""
-
- opts.on("-h", "--help",
- "Show this help message.") { puts opts; exit }
-
- opts.parse!
+require 'active_support'
+
+server = case ARGV.first
+ when "lighttpd"
+ ARGV.shift
+ when "webrick"
+ ARGV.shift
+ else
+ if RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
+ "lighttpd"
+ else
+ "webrick"
+ end
end
-ENV["RAILS_ENV"] = OPTIONS[:environment]
-RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
-
-require RAILS_ROOT + "/config/environment"
-require 'webrick_server'
-
-OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
+if server == "webrick"
+ puts "=> Booting WEBrick..."
+else
+ puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
+end
-puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
-puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
-DispatchServlet.dispatch(OPTIONS)
+require "commands/servers/#{server}" \ No newline at end of file