Froze rails gems
[depot.git] / vendor / rails / railties / lib / commands / servers / webrick.rb
1 require 'webrick'
2 require 'optparse'
3 require 'commands/servers/base'
4
5 OPTIONS = {
6 :port => 3000,
7 :ip => "0.0.0.0",
8 :environment => (ENV['RAILS_ENV'] || "development").dup,
9 :server_root => File.expand_path(RAILS_ROOT + "/public/"),
10 :server_type => WEBrick::SimpleServer,
11 :charset => "UTF-8",
12 :mime_types => WEBrick::HTTPUtils::DefaultMimeTypes,
13 :debugger => false
14
15 }
16
17 ARGV.options do |opts|
18 script_name = File.basename($0)
19 opts.banner = "Usage: ruby #{script_name} [options]"
20
21 opts.separator ""
22
23 opts.on("-p", "--port=port", Integer,
24 "Runs Rails on the specified port.",
25 "Default: 3000") { |v| OPTIONS[:port] = v }
26 opts.on("-b", "--binding=ip", String,
27 "Binds Rails to the specified ip.",
28 "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
29 opts.on("-e", "--environment=name", String,
30 "Specifies the environment to run this server under (test/development/production).",
31 "Default: development") { |v| OPTIONS[:environment] = v }
32 opts.on("-m", "--mime-types=filename", String,
33 "Specifies an Apache style mime.types configuration file to be used for mime types",
34 "Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
35
36 opts.on("-d", "--daemon",
37 "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
38 ) { OPTIONS[:server_type] = WEBrick::Daemon }
39
40 opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true }
41
42 opts.on("-c", "--charset=charset", String,
43 "Set default charset for output.",
44 "Default: UTF-8") { |v| OPTIONS[:charset] = v }
45
46 opts.separator ""
47
48 opts.on("-h", "--help",
49 "Show this help message.") { puts opts; exit }
50
51 opts.parse!
52 end
53
54 start_debugger if OPTIONS[:debugger]
55
56 ENV["RAILS_ENV"] = OPTIONS[:environment]
57 RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
58
59 require RAILS_ROOT + "/config/environment"
60 require 'webrick_server'
61
62 OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
63
64 puts "=> Rails #{Rails.version} application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
65 puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
66 DispatchServlet.dispatch(OPTIONS)