diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-03-01 14:43:04 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-03-03 11:13:12 -0800 |
commit | 723254df772154e2790b26923d4827a096c53428 (patch) | |
tree | 4f790b95a910e3f379dd5199341bd877c4f7e6ae /bin/unicorn | |
parent | 9a7e1f1a7e986a59eb4be9b6a4d093f3366c9c72 (diff) | |
download | unicorn-723254df772154e2790b26923d4827a096c53428.tar.gz |
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.
Diffstat (limited to 'bin/unicorn')
-rwxr-xr-x | bin/unicorn | 39 |
1 files changed, 23 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 |