Froze rails gems
[depot.git] / vendor / rails / railties / lib / commands / servers / mongrel.rb
1 require 'rbconfig'
2 require 'commands/servers/base'
3
4 unless defined?(Mongrel)
5 puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
6 exit 1
7 end
8
9 require 'optparse'
10
11 OPTIONS = {
12 :port => 3000,
13 :ip => "0.0.0.0",
14 :environment => (ENV['RAILS_ENV'] || "development").dup,
15 :detach => false,
16 :debugger => false
17 }
18
19 ARGV.clone.options do |opts|
20 opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
21 opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
22 opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
23 opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true }
24 opts.on("-e", "--environment=name", String,
25 "Specifies the environment to run this server under (test/development/production).",
26 "Default: development") { |v| OPTIONS[:environment] = v }
27
28 opts.separator ""
29
30 opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
31
32 opts.parse!
33 end
34
35 puts "=> Rails #{Rails.version} application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
36
37 parameters = [
38 "start",
39 "-p", OPTIONS[:port].to_s,
40 "-a", OPTIONS[:ip].to_s,
41 "-e", OPTIONS[:environment],
42 "-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid"
43 ]
44
45 if OPTIONS[:detach]
46 `mongrel_rails #{parameters.join(" ")} -d`
47 else
48 ENV["RAILS_ENV"] = OPTIONS[:environment]
49 RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
50
51 start_debugger if OPTIONS[:debugger]
52
53 puts "=> Call with -d to detach"
54 puts "=> Ctrl-C to shutdown server"
55
56 log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath
57 open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log
58 tail_thread = tail(log)
59
60 trap(:INT) { exit }
61
62 begin
63 silence_warnings { ARGV = parameters }
64 load("mongrel_rails")
65 ensure
66 tail_thread.kill if tail_thread
67 puts 'Exiting'
68 end
69 end