about summary refs log tree commit homepage
path: root/bin/unicorn_rails
diff options
context:
space:
mode:
Diffstat (limited to 'bin/unicorn_rails')
-rwxr-xr-xbin/unicorn_rails31
1 files changed, 18 insertions, 13 deletions
diff --git a/bin/unicorn_rails b/bin/unicorn_rails
index b3fda7b..b1458fc 100755
--- a/bin/unicorn_rails
+++ b/bin/unicorn_rails
@@ -1,4 +1,5 @@
-#!/home/ew/bin/ruby
+#!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
+# -*- encoding: binary -*-
 require 'unicorn/launcher'
 require 'optparse'
 require 'fileutils'
@@ -11,7 +12,6 @@ options = { :listeners => listeners }
 host, port = Unicorn::Const::DEFAULT_HOST, Unicorn::Const::DEFAULT_PORT
 set_listener = false
 ENV['RAILS_ENV'] ||= "development"
-map_path = ENV['RAILS_RELATIVE_URL_ROOT']
 
 opts = OptionParser.new("", 24, '  ') do |opts|
   opts.banner = "Usage: #{cmd} " \
@@ -57,8 +57,8 @@ opts = OptionParser.new("", 24, '  ') do |opts|
     set_listener = true
   end
 
-  opts.on("-E", "--env ENVIRONMENT",
-          "use ENVIRONMENT for defaults (default: development)") do |e|
+  opts.on("-E", "--env RAILS_ENV",
+          "use RAILS_ENV for defaults (default: development)") do |e|
     ENV['RAILS_ENV'] = e
   end
 
@@ -75,12 +75,18 @@ opts = OptionParser.new("", 24, '  ') do |opts|
   end
 
   opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
-    options[:config_file] = File.expand_path(f)
+    options[:config_file] = f
   end
 
-  opts.on("-P", "--path PATH", "Runs Rails app mounted at a specific path.",
-          "(default: /") do |v|
-    ENV['RAILS_RELATIVE_URL_ROOT'] = map_path = v
+  opts.on("-P PATH", "DEPRECATED") do |v|
+    warn %q{Use of -P is ambiguous and discouraged}
+    warn %q{Use --path or RAILS_RELATIVE_URL_ROOT instead}
+    ENV['RAILS_RELATIVE_URL_ROOT'] = v
+  end
+
+  opts.on("--path PATH", "Runs Rails app mounted at a specific path.",
+          "(default: /)") do |v|
+    ENV['RAILS_RELATIVE_URL_ROOT'] = v
   end
 
   # I'm avoiding Unicorn-specific config options on the command-line.
@@ -91,7 +97,7 @@ opts = OptionParser.new("", 24, '  ') do |opts|
   opts.separator "Common options:"
 
   opts.on_tail("-h", "--help", "Show this message") do
-    puts opts
+    puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
     exit
   end
 
@@ -140,7 +146,6 @@ app = lambda do ||
     end
 
     if old_rails
-      require 'rack'
       require 'unicorn/app/old_rails'
       Unicorn::App::OldRails.new
     else
@@ -148,14 +153,15 @@ app = lambda do ||
     end
   when /\.ru$/
     raw = File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) }
+    raw.sub!(/^__END__\n.*/, '')
     eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config)
   else
     require config
     Object.const_get(File.basename(config, '.rb').capitalize)
   end
 
-  map_path ||= '/'
   Rack::Builder.new do
+    map_path = ENV['RAILS_RELATIVE_URL_ROOT'] || '/'
     if inner_app.class.to_s == "Unicorn::App::OldRails"
       if map_path != '/'
         # patches + tests welcome, but I really cbf to deal with this
@@ -165,7 +171,6 @@ app = lambda do ||
       $stderr.puts "LogTailer not available for Rails < 2.3" unless daemonize
       $stderr.puts "Debugger not available" if $DEBUG
       map(map_path) do
-        require 'unicorn/app/old_rails/static'
         use Unicorn::App::OldRails::Static
         run inner_app
       end
@@ -197,6 +202,6 @@ end
 
 if daemonize
   options[:pid] = rails_pid
-  Unicorn::Launcher.daemonize!
+  Unicorn::Launcher.daemonize!(options)
 end
 Unicorn.run(app, options)