aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-11-19 21:52:14 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-11-19 21:52:14 +0000
commitee8121fc7691eea954fb431bc604e82eeb982bf5 (patch)
treeebfb144a75f3e4454808284a1324d56d400569fb /railties/lib
parent5999fdd3f30c64e340b64be1a64aa16323c6c69e (diff)
downloadrails-ee8121fc7691eea954fb431bc604e82eeb982bf5.tar.gz
rails-ee8121fc7691eea954fb431bc604e82eeb982bf5.tar.bz2
rails-ee8121fc7691eea954fb431bc604e82eeb982bf5.zip
Make script/server work with -d and -e on Mongrel
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5575 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/commands/servers/mongrel.rb73
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