2005-11-07 05:42:52 -05:00
|
|
|
require 'webrick'
|
|
|
|
require 'optparse'
|
2007-09-25 15:08:50 -04:00
|
|
|
require 'commands/servers/base'
|
2005-11-07 05:42:52 -05:00
|
|
|
|
|
|
|
OPTIONS = {
|
2007-04-28 11:57:29 -04:00
|
|
|
: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,
|
|
|
|
:debugger => false
|
|
|
|
|
2005-11-07 05:42:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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.",
|
2006-06-28 16:53:00 -04:00
|
|
|
"Default: 3000") { |v| OPTIONS[:port] = v }
|
2005-11-07 05:42:52 -05:00
|
|
|
opts.on("-b", "--binding=ip", String,
|
|
|
|
"Binds Rails to the specified ip.",
|
2006-06-28 16:53:00 -04:00
|
|
|
"Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
|
2005-11-07 05:42:52 -05:00
|
|
|
opts.on("-e", "--environment=name", String,
|
|
|
|
"Specifies the environment to run this server under (test/development/production).",
|
2006-06-28 16:53:00 -04:00
|
|
|
"Default: development") { |v| OPTIONS[:environment] = v }
|
2005-11-07 05:42:52 -05:00
|
|
|
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 }
|
|
|
|
|
2007-04-28 11:57:29 -04:00
|
|
|
opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true }
|
|
|
|
|
2005-11-07 05:42:52 -05:00
|
|
|
opts.on("-c", "--charset=charset", String,
|
|
|
|
"Set default charset for output.",
|
2006-06-28 16:53:00 -04:00
|
|
|
"Default: UTF-8") { |v| OPTIONS[:charset] = v }
|
2005-11-07 05:42:52 -05:00
|
|
|
|
|
|
|
opts.separator ""
|
|
|
|
|
|
|
|
opts.on("-h", "--help",
|
|
|
|
"Show this help message.") { puts opts; exit }
|
|
|
|
|
|
|
|
opts.parse!
|
|
|
|
end
|
|
|
|
|
2007-04-28 11:57:29 -04:00
|
|
|
start_debugger if OPTIONS[:debugger]
|
|
|
|
|
2005-11-07 05:42:52 -05:00
|
|
|
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)
|
|
|
|
|
2008-05-22 07:06:27 -04:00
|
|
|
puts "=> Rails #{Rails.version} application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
2005-11-07 05:42:52 -05:00
|
|
|
puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
|
|
|
DispatchServlet.dispatch(OPTIONS)
|