aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/server.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-29 12:18:51 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-29 12:18:51 +0000
commit0a0ac868453e9d8d9ee1dac6a7eb274772235b05 (patch)
tree1db7e1fce4d2c62f97c204ef72e7898c5263c82a /railties/lib/commands/server.rb
parent070d218c479c8cbb41e78f599110f0ea1cf0343a (diff)
downloadrails-0a0ac868453e9d8d9ee1dac6a7eb274772235b05.tar.gz
rails-0a0ac868453e9d8d9ee1dac6a7eb274772235b05.tar.bz2
rails-0a0ac868453e9d8d9ee1dac6a7eb274772235b05.zip
Removed all the scripts in script/* and replaced it with one generic portal: script/run
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2411 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/commands/server.rb')
-rw-r--r--railties/lib/commands/server.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb
new file mode 100644
index 0000000000..5330c050b9
--- /dev/null
+++ b/railties/lib/commands/server.rb
@@ -0,0 +1,57 @@
+require 'webrick'
+require 'optparse'
+
+OPTIONS = {
+ :port => 3000,
+ :ip => "0.0.0.0",
+ :environment => "development",
+ :server_root => File.expand_path(File.dirname(__FILE__) + "/../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!
+end
+
+ENV["RAILS_ENV"] = OPTIONS[:environment]
+require File.dirname(__FILE__) + "/../config/environment"
+require 'webrick_server'
+
+OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
+
+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)