1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/commands/servers/mongrel.rb
David Heinemeier Hansson 44de099efe Restore windows compatibility
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5577 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-19 22:17:26 +00:00

57 lines
No EOL
1.7 KiB
Ruby

require 'rbconfig'
require 'commands/servers/base'
unless defined?(Mongrel)
puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
exit 1
end
require 'optparse'
OPTIONS = {
:port => 3000,
:ip => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
:detach => false
}
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 }
opts.separator ""
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
opts.parse!
end
puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
if OPTIONS[:detach]
`mongrel_rails start -d -p #{OPTIONS[:port]} -a #{OPTIONS[:ip]} -e #{OPTIONS[:environment]}`
else
require 'initializer'
Rails::Initializer.run(:initialize_logger)
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
silence_warnings do
ARGV = [ "start", "-p", OPTIONS[:port].to_s, "-a", OPTIONS[:ip].to_s, "-e", OPTIONS[:environment] ]
end
load("mongrel_rails")
ensure
tail_thread.kill if tail_thread
puts 'Exiting'
end
end