From 723254df772154e2790b26923d4827a096c53428 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 1 Mar 2009 14:43:04 -0800 Subject: Begin to allow deferred app creation/loading Some applications do not handle loading before forking out-of-the-box very gracefully, this starts adding support to build the Rack(-ish) application later in the process. --- bin/unicorn | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'bin') 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 -- cgit v1.2.3-24-ge0c7