diff options
Diffstat (limited to 'railties/lib/commands')
-rw-r--r-- | railties/lib/commands/servers/mongrel.rb | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/railties/lib/commands/servers/mongrel.rb b/railties/lib/commands/servers/mongrel.rb index 6e401adba2..558a5dac31 100644 --- a/railties/lib/commands/servers/mongrel.rb +++ b/railties/lib/commands/servers/mongrel.rb @@ -6,57 +6,48 @@ unless defined?(Mongrel) exit 1 end -require 'initializer' -Rails::Initializer.run(:initialize_logger) - require 'optparse' -detach = false -ip = nil -port = nil -mime = 'config/mime.yml' - -ARGV.clone.options do |opt| - opt.on("-p", "--port=port", Integer, - "Runs Rails on the specified port.", - "Default: 3000") { |p| port = p } - opt.on("-a", "--address=ip", String, - "Binds Rails to the specified ip.", - "Default: 0.0.0.0") { |i| ip = i } - opt.on("-m", "--mime=path", String, - "Path to custom mime file.", - "Default: config/mime.yml (if it exists)") { |m| mime = m } - opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 } - opt.on('-d', '-d', 'Call with -d to detach') { detach = true } - opt.parse! -end +OPTIONS = { + :port => 3000, + :ip => "0.0.0.0", + :environment => (ENV['RAILS_ENV'] || "development").dup, + :detach => false +} -default_port, default_ip = 3000, '0.0.0.0' -puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}" +ARGV.clone.options do |opts| + opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v } + opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v } + opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true } + opts.on("-e", "--environment=name", String, + "Specifies the environment to run this server under (test/development/production).", + "Default: development") { |v| OPTIONS[:environment] = v } -log_file = Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath + opts.separator "" -tail_thread = nil + opts.on("-h", "--help", "Show this help message.") { puts opts; exit } -if !detach - puts "=> Call with -d to detach" - puts "=> Ctrl-C to shutdown server" - detach = false - tail_thread = tail(log_file) + opts.parse! end -trap(:INT) { exit } +puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}" -if File.exist?(File.join(RAILS_ROOT, mime)) && !ARGV.any? { |a| a =~ /^--?m/ } - ARGV << "--mime=#{mime}" -end +if OPTIONS[:detach] + `mongrel_rails start -d -p #{OPTIONS[:port]} -a #{OPTIONS[:ip]} -e #{OPTIONS[:environment]}` +else + require 'initializer' + Rails::Initializer.run(:initialize_logger) -begin - ARGV.unshift("start") - load 'mongrel_rails' -ensure - unless detach + puts "=> Call with -d to detach" + puts "=> Ctrl-C to shutdown server" + tail_thread = tail(Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath) + + trap(:INT) { exit } + + begin + `mongrel_rails start -p #{OPTIONS[:port]} -a #{OPTIONS[:ip]} -e #{OPTIONS[:environment]}` + ensure tail_thread.kill if tail_thread puts 'Exiting' end -end +end
\ No newline at end of file |