1
require 'active_support'
2
require 'action_controller'
7
# TODO: Push Thin adapter upstream so we don't need worry about requiring it
9
require_library_or_gem 'thin'
17
:environment => (ENV['RAILS_ENV'] || "development").dup,
18
:config => RAILS_ROOT + "/config.ru",
24
ARGV.clone.options do |opts|
25
opts.on("-p", "--port=port", Integer,
26
"Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
27
opts.on("-b", "--binding=ip", String,
28
"Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
29
opts.on("-c", "--config=file", String,
30
"Use custom rackup configuration file") { |v| options[:config] = v }
31
opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true }
32
opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
33
opts.on("-e", "--environment=name", String,
34
"Specifies the environment to run this server under (test/development/production).",
35
"Default: development") { |v| options[:environment] = v }
36
opts.on("-P", "--path=/path", String, "Runs Rails app mounted at a specific path.", "Default: /") { |v| options[:path] = v }
40
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
45
server = Rack::Handler.get(ARGV.first) rescue nil
48
server = Rack::Handler::Mongrel
50
server = Rack::Handler::WEBrick
54
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
55
puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{options[:path]}"
57
%w(cache pids sessions sockets).each do |dir_to_make|
58
FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make))
63
pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
64
File.open(pid, 'w'){ |f| f.write(Process.pid) }
65
at_exit { File.delete(pid) if File.exist?(pid) }
68
ENV["RAILS_ENV"] = options[:environment]
69
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
71
if File.exist?(options[:config])
72
config = options[:config]
74
cfgfile = File.read(config)
75
if cfgfile[/^#\\(.*)/]
76
opts.parse!($1.split(/\s+/))
78
inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config)
81
inner_app = Object.const_get(File.basename(config, '.rb').capitalize)
84
require RAILS_ROOT + "/config/environment"
85
inner_app = ActionController::Dispatcher.new
88
if options[:path].nil?
91
ActionController::Base.relative_url_root = options[:path]
92
map_path = options[:path]
95
app = Rack::Builder.new {
96
use Rails::Rack::LogTailer unless options[:detach]
97
use Rails::Rack::Debugger if options[:debugger]
99
use Rails::Rack::Static
104
puts "=> Call with -d to detach"
108
puts "=> Ctrl-C to shutdown server"
111
server.run(app, options.merge(:AccessLog => []))