about summary refs log tree commit homepage
path: root/bin/unicorn
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2018-09-13 10:48:25 -0700
committerEric Wong <e@80x24.org>2018-09-21 00:29:11 +0000
commit5985dd50a9bd72388dd5ca4886d6dffc083f87d4 (patch)
treea62dec60cfbfa8d0641207352f89b0538eef0319 /bin/unicorn
parentc93a392385e7fe1ca3bf86cabe04f7591cef1a58 (diff)
downloadunicorn-5985dd50a9bd72388dd5ca4886d6dffc083f87d4.tar.gz
This allows for the equivalent of the
-N/--no-default_middleware command line option to be
specified in the configuration file so it doesn't
need to be specified on the command line every time
unicorn is executed.

It explicitly excludes the use of -N/--no-default_middleware
as an embedded configuration option in the rackup file, by
ignoring the options after ARGV is parsed.

In order to allow the configuration method to work, have
the lambda that Unicorn.builder returns accept two arguments.
Technically, only one argument is needed for the HttpServer
instance, but I'm guessing if the lambda accepts a single
argument, we expect that to be a rack application instead
of a lambda that returns a rack application.

The command line option option to disable default middleware
will take precedence over the unicorn configuration file option
if both are present.

For backwards compatibility, if the lambda passed to
HttpServer accepts 0 arguments, then call it without
arguments.

[ew: fix precedence for arity checking in build_app!
     configurator: ensure -N is respected when set in command-line]
Diffstat (limited to 'bin/unicorn')
-rwxr-xr-xbin/unicorn4
1 files changed, 3 insertions, 1 deletions
diff --git a/bin/unicorn b/bin/unicorn
index 3c5e5cb..00c8464 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -6,6 +6,7 @@ require 'optparse'
 ENV["RACK_ENV"] ||= "development"
 rackup_opts = Unicorn::Configurator::RACKUP
 options = rackup_opts[:options]
+set_no_default_middleware = true
 
 op = OptionParser.new("", 24, '  ') do |opts|
   cmd = File.basename($0)
@@ -60,7 +61,7 @@ op = OptionParser.new("", 24, '  ') do |opts|
 
   opts.on("-N", "--no-default-middleware",
           "do not load middleware implied by RACK_ENV") do |e|
-    rackup_opts[:no_default_middleware] = true
+    rackup_opts[:no_default_middleware] = true if set_no_default_middleware
   end
 
   opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
@@ -110,6 +111,7 @@ op = OptionParser.new("", 24, '  ') do |opts|
   opts.parse! ARGV
 end
 
+set_no_default_middleware = false
 app = Unicorn.builder(ARGV[0] || 'config.ru', op)
 op = nil