diff options
Diffstat (limited to 'bin/unicorn')
-rwxr-xr-x | bin/unicorn | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/bin/unicorn b/bin/unicorn index a34d9bc..5af021d 100755 --- a/bin/unicorn +++ b/bin/unicorn @@ -1,8 +1,9 @@ -#!/home/ew/bin/ruby +#!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby +# -*- encoding: binary -*- require 'unicorn/launcher' require 'optparse' -env = "development" +ENV["RACK_ENV"] ||= "development" daemonize = false listeners = [] options = { :listeners => listeners } @@ -57,15 +58,17 @@ opts = OptionParser.new("", 24, ' ') do |opts| opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") do |e| - env = e + ENV["RACK_ENV"] = e end opts.on("-D", "--daemonize", "run daemonized in the background") do |d| daemonize = d ? true : false end - opts.on("-P", "--pid FILE", "file to store PID (default: none)") do |f| - options[:pid] = File.expand_path(f) + opts.on("-P", "--pid FILE", "DEPRECATED") do |f| + warn %q{Use of --pid/-P is strongly discouraged} + warn %q{Use the 'pid' directive in the Unicorn config file instead} + options[:pid] = f end opts.on("-s", "--server SERVER", @@ -82,7 +85,7 @@ 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 # I'm avoiding Unicorn-specific config options on the command-line. @@ -93,7 +96,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 @@ -120,17 +123,17 @@ require 'pp' if $DEBUG app = lambda do || # require Rack as late as possible in case $LOAD_PATH is modified # in config.ru or command-line - require 'rack' inner_app = case config 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 pp({ :inner_app => inner_app }) if $DEBUG - case env + case ENV["RACK_ENV"] when "development" Rack::Builder.new do use Rack::CommonLogger, $stderr @@ -158,5 +161,5 @@ if $DEBUG }) end -Unicorn::Launcher.daemonize! if daemonize +Unicorn::Launcher.daemonize!(options) if daemonize Unicorn.run(app, options) |