From aa2208a0574c395cf91ce7ff82e978895aa8b1b7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 30 Mar 2009 01:29:20 -0700 Subject: bin/*: parse CLI switches in config.ru sooner This allows config.ru to specify listener and stuff before we setup the application. --- bin/unicorn | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'bin/unicorn') diff --git a/bin/unicorn b/bin/unicorn index da77198..6247f32 100755 --- a/bin/unicorn +++ b/bin/unicorn @@ -105,22 +105,25 @@ opts = OptionParser.new("", 24, ' ') do |opts| opts.parse! ARGV end +config = ARGV[0] || "config.ru" +abort "configuration file #{config} not found" unless File.exist?(config) + +if config =~ /\.ru$/ + # parse embedded command-line options in config.ru comments + if File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) } =~ /^#\\(.*)/ + opts.parse! $1.split(/\s+/) + end +end + require 'pp' if $DEBUG # require Rack as late as possible in case $LOAD_PATH is modified # in config.ru or command-line require 'rack' -config = ARGV[0] || "config.ru" -abort "configuration file #{config} not found" unless File.exist?(config) - inner_app = case config when /\.ru$/ raw = File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) } - # parse embedded command-line options in config.ru comments - if raw[/^#\\(.*)/] - opts.parse! $1.split(/\s+/) - end lambda { || eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config) } else lambda do || -- cgit v1.2.3-24-ge0c7