diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-03-30 01:29:20 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-03-30 01:29:20 -0700 |
commit | aa2208a0574c395cf91ce7ff82e978895aa8b1b7 (patch) | |
tree | 9280035536799aace87da763c088d170c6466d26 | |
parent | fa5d9473deaa345e5ca76375fbe21aaae3516b89 (diff) | |
download | unicorn-aa2208a0574c395cf91ce7ff82e978895aa8b1b7.tar.gz |
This allows config.ru to specify listener and stuff before we setup the application.
-rwxr-xr-x | bin/unicorn | 17 | ||||
-rwxr-xr-x | bin/unicorn_rails | 16 |
2 files changed, 19 insertions, 14 deletions
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 || diff --git a/bin/unicorn_rails b/bin/unicorn_rails index 172d572..d0794eb 100755 --- a/bin/unicorn_rails +++ b/bin/unicorn_rails @@ -105,6 +105,15 @@ opts = OptionParser.new("", 24, ' ') do |opts| opts.parse! ARGV end +config = ARGV[0] || (File.exist?('config.ru') ? 'config.ru' : nil) + +if config && 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 # Loads Rails and the private version of Rack it bundles. Returns a @@ -121,8 +130,6 @@ rails_loader = lambda do || abort "#$0 must be run inside RAILS_ROOT (#{::RAILS_ROOT})" end - # return the lambda - config = ::ARGV[0] || (File.exist?('config.ru') ? 'config.ru' : nil) case config when nil lambda do || @@ -146,11 +153,6 @@ rails_loader = lambda do || end 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+/) - require 'pp' if $DEBUG - end lambda { || eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config) } else lambda do || |