diff options
-rwxr-xr-x | bin/unicorn | 39 | ||||
-rw-r--r-- | lib/unicorn.rb | 5 |
2 files changed, 28 insertions, 16 deletions
diff --git a/bin/unicorn b/bin/unicorn index e03c713..1ea3d1f 100755 --- a/bin/unicorn +++ b/bin/unicorn @@ -105,30 +105,37 @@ require 'pp' if $DEBUG config = ARGV[0] || "config.ru" abort "configuration file #{config} not found" unless File.exist?(config) -if config =~ /\.ru$/ - cfgfile = File.read(config) - if cfgfile[/^#\\(.*)/] +inner_app = case config +when /\.ru$/ + raw = File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) } + if raw[/^#\\(.*)/] warn %(not parsing embedded command-line options: "#$1") end - inner_app = eval "Rack::Builder.new {(#{cfgfile}\n)}.to_app", nil, config + lambda { || eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config) } else - require config - inner_app = Object.const_get(File.basename(config, '.rb').capitalize) + lambda do || + require config + Object.const_get(File.basename(config, '.rb').capitalize) + end end app = case env when "development" - Rack::Builder.new do - use Rack::CommonLogger, STDERR - use Rack::ShowExceptions - use Rack::Lint - run inner_app - end.to_app + lambda do || + Rack::Builder.new do + use Rack::CommonLogger, STDERR + use Rack::ShowExceptions + use Rack::Lint + run inner_app.call + end.to_app + end when "deployment" - Rack::Builder.new do - use Rack::CommonLogger, STDERR - run inner_app - end.to_app + lambda do || + Rack::Builder.new do + use Rack::CommonLogger, STDERR + run inner_app.call + end.to_app + end else inner_app end diff --git a/lib/unicorn.rb b/lib/unicorn.rb index aad4c3d..fa2ebe8 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -86,6 +86,7 @@ module Unicorn config_listeners.each { |addr| listen(addr) } listen(Const::DEFAULT_LISTENER) if @listeners.empty? self.pid = @config[:pid] + build_app! spawn_missing_workers self end @@ -529,5 +530,9 @@ module Unicorn listeners.map { |io| sock_name(io) } end + def build_app! + @app = @app.call if @app.respond_to?(:arity) && @app.arity == 0 + end + end end |