Skip to content
This repository
Browse code

Made script/server work with -e and -d when using Mongrel [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5578 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b93e4692b26d348f229095d87fba02fb1efdbe9f 1 parent 30e5436
David Heinemeier Hansson dhh authored
4 railties/CHANGELOG
... ... @@ -1,8 +1,6 @@
1 1 *1.2.0 RC1* (November 8th, 2006)
2 2
3   -* Use custom mime file for script/server mongrel if config/mime.yml exists. Pass --mime=other/path for a custom mime file. [Rick Olson]
4   -
5   -* Add custom mime type file for mongrel. config/mime.yml is added with generated apps from the rails command. [Rick Olson]
  3 +* Made script/server work with -e and -d when using Mongrel [DHH]
6 4
7 5 * Update to Prototype 1.5.0_rc2 [5550] which makes it work in Opera again [Thomas Fuchs]
8 6
2  railties/lib/commands/servers/lighttpd.rb
@@ -62,7 +62,7 @@
62 62 default_port, default_ip = 3000, '0.0.0.0'
63 63 port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port
64 64 ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
65   -puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
  65 +puts "=> Rails application starting on http://#{ip || default_ip}:#{port || default_port}"
66 66
67 67 tail_thread = nil
68 68
75 railties/lib/commands/servers/mongrel.rb
@@ -6,57 +6,52 @@
6 6 exit 1
7 7 end
8 8
9   -require 'initializer'
10   -Rails::Initializer.run(:initialize_logger)
11   -
12 9 require 'optparse'
13 10
14   -detach = false
15   -ip = nil
16   -port = nil
17   -mime = 'config/mime.yml'
18   -
19   -ARGV.clone.options do |opt|
20   - opt.on("-p", "--port=port", Integer,
21   - "Runs Rails on the specified port.",
22   - "Default: 3000") { |p| port = p }
23   - opt.on("-a", "--address=ip", String,
24   - "Binds Rails to the specified ip.",
25   - "Default: 0.0.0.0") { |i| ip = i }
26   - opt.on("-m", "--mime=path", String,
27   - "Path to custom mime file.",
28   - "Default: config/mime.yml (if it exists)") { |m| mime = m }
29   - opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
30   - opt.on('-d', '-d', 'Call with -d to detach') { detach = true }
31   - opt.parse!
32   -end
  11 +OPTIONS = {
  12 + :port => 3000,
  13 + :ip => "0.0.0.0",
  14 + :environment => (ENV['RAILS_ENV'] || "development").dup,
  15 + :detach => false
  16 +}
  17 +
  18 +ARGV.clone.options do |opts|
  19 + opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
  20 + opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
  21 + opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
  22 + opts.on("-e", "--environment=name", String,
  23 + "Specifies the environment to run this server under (test/development/production).",
  24 + "Default: development") { |v| OPTIONS[:environment] = v }
33 25
34   -default_port, default_ip = 3000, '0.0.0.0'
35   -puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
  26 + opts.separator ""
36 27
37   -log_file = Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath
  28 + opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
  29 +
  30 + opts.parse!
  31 +end
38 32
39   -tail_thread = nil
  33 +puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
  34 +
  35 +if OPTIONS[:detach]
  36 + `mongrel_rails start -d -p #{OPTIONS[:port]} -a #{OPTIONS[:ip]} -e #{OPTIONS[:environment]}`
  37 +else
  38 + require 'initializer'
  39 + Rails::Initializer.run(:initialize_logger)
40 40
41   -if !detach
42 41 puts "=> Call with -d to detach"
43 42 puts "=> Ctrl-C to shutdown server"
44   - detach = false
45   - tail_thread = tail(log_file)
46   -end
  43 + tail_thread = tail(Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath)
47 44
48   -trap(:INT) { exit }
  45 + trap(:INT) { exit }
49 46
50   -if File.exist?(File.join(RAILS_ROOT, mime)) && !ARGV.any? { |a| a =~ /^--?m/ }
51   - ARGV << "--mime=#{mime}"
52   -end
  47 + begin
  48 + silence_warnings do
  49 + ARGV = [ "start", "-p", OPTIONS[:port].to_s, "-a", OPTIONS[:ip].to_s, "-e", OPTIONS[:environment] ]
  50 + end
53 51
54   -begin
55   - ARGV.unshift("start")
56   - load 'mongrel_rails'
57   -ensure
58   - unless detach
  52 + load("mongrel_rails")
  53 + ensure
59 54 tail_thread.kill if tail_thread
60 55 puts 'Exiting'
61 56 end
62   -end
  57 +end

0 comments on commit b93e469

Please sign in to comment.
Something went wrong with that request. Please try again.