unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: [PATCH] Add -N or --no-default-middleware option.
  2013-01-29  3:52  6% ` Eric Wong
  2013-01-29  4:02  6%   ` Eric Wong
@ 2013-01-29  4:03  7%   ` Lin Jen-Shin (godfat)
  1 sibling, 0 replies; 5+ results
From: Lin Jen-Shin (godfat) @ 2013-01-29  4:03 UTC (permalink / raw)
  To: Eric Wong; +Cc: unicorn list

On Tue, Jan 29, 2013 at 11:52 AM, Eric Wong <normalperson@yhbt.net> wrote:
> Lin Jen-Shin <godfat@godfat.org> wrote:
>> +  opts.on("-N", "--no-default-middleware",
>> +          "no default middleware even if RACK_ENV is development") do |e|
>
> RACK_ENV=deployment also loads middleware, so I think it's more accurate
> with:
>
>         do not load middleware implied by RACK_ENV
>
> This also puts us back within the 80-column limit imposed by "test_help"
> in test/exec/test_exec.rb

Oh right, I only remembered to keep the source within 80-column limit,
but forgot that the output might be longer than source. Thanks for the
better wordings. I updated the patch for Zbatery, but it's too late
for Rainbows though.

> Will sign-off and push that change squashed unless there are objections.

Surely, thanks!

> I also just bumped master to rack 1.5.1, which fixes the Rack::Lint
> test regression in 1.5.0.
>
> Will pull in the "hijack" branch into master soon (and release 4.6.0)
> since all my questions about it have been answered in rack-devel.

I haven't had a chance to read hijack more, looking forward to it :)
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[relevance 7%]

* Re: [PATCH] Add -N or --no-default-middleware option.
  2013-01-29  3:52  6% ` Eric Wong
@ 2013-01-29  4:02  6%   ` Eric Wong
  2013-01-29  4:03  7%   ` Lin Jen-Shin (godfat)
  1 sibling, 0 replies; 5+ results
From: Eric Wong @ 2013-01-29  4:02 UTC (permalink / raw)
  To: unicorn list; +Cc: Lin Jen-Shin

Eric Wong <normalperson@yhbt.net> wrote:
> Lin Jen-Shin <godfat@godfat.org> wrote:
> > +  opts.on("-N", "--no-default-middleware",
> > +          "no default middleware even if RACK_ENV is development") do |e|
> 
> RACK_ENV=deployment also loads middleware, so I think it's more accurate
> with:
> 
> 	do not load middleware implied by RACK_ENV
> 
> This also puts us back within the 80-column limit imposed by "test_help"
> in test/exec/test_exec.rb

Heh, turns out there's a bug in test_exec.rb (but I still don't think
mentioning "development" for this help is correct)

>From ee3ada3c697311ab0a799fcdc492ae062e7d5128 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Tue, 29 Jan 2013 03:56:16 +0000
Subject: [PATCH] test_exec: do not count '\n' as column width

This off-by-one error was incorrectly rejecting a line which
would've been readable without wrapping on an 80-column terminal.
---
 test/exec/test_exec.rb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index 1cee2b7..10a1bae 100644
--- a/test/exec/test_exec.rb
+++ b/test/exec/test_exec.rb
@@ -323,6 +323,7 @@ EOF
     # mobile phone or netbook on a slow connection :)
     assert lines.size <= 24, "help height fits in an ANSI terminal window"
     lines.each do |line|
+      line.chomp!
       assert line.size <= 80, "help width fits in an ANSI terminal window"
     end
   end
-- 
1.8.1.1.253.g2934a48

_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply related	[relevance 6%]

* Re: [PATCH] Add -N or --no-default-middleware option.
  2013-01-29  3:21  5% [PATCH] Add -N or --no-default-middleware option Lin Jen-Shin
@ 2013-01-29  3:52  6% ` Eric Wong
  2013-01-29  4:02  6%   ` Eric Wong
  2013-01-29  4:03  7%   ` Lin Jen-Shin (godfat)
  0 siblings, 2 replies; 5+ results
From: Eric Wong @ 2013-01-29  3:52 UTC (permalink / raw)
  To: unicorn list; +Cc: Lin Jen-Shin

Lin Jen-Shin <godfat@godfat.org> wrote:
> +  opts.on("-N", "--no-default-middleware",
> +          "no default middleware even if RACK_ENV is development") do |e|

RACK_ENV=deployment also loads middleware, so I think it's more accurate
with:

	do not load middleware implied by RACK_ENV

This also puts us back within the 80-column limit imposed by "test_help"
in test/exec/test_exec.rb

Will sign-off and push that change squashed unless there are objections.

I also just bumped master to rack 1.5.1, which fixes the Rack::Lint
test regression in 1.5.0.

Will pull in the "hijack" branch into master soon (and release 4.6.0)
since all my questions about it have been answered in rack-devel.
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[relevance 6%]

* [PATCH] Add -N or --no-default-middleware option.
@ 2013-01-29  3:21  5% Lin Jen-Shin
  2013-01-29  3:52  6% ` Eric Wong
  0 siblings, 1 reply; 5+ results
From: Lin Jen-Shin @ 2013-01-29  3:21 UTC (permalink / raw)
  To: mongrel-unicorn; +Cc: Lin Jen-Shin

This would prevent Unicorn from adding default middleware,
as if RACK_ENV were always none. (not development nor deployment)

This should also be applied to `rainbows' and `zbatery' as well.

One of the reasons to add this is to avoid conflicting
RAILS_ENV and RACK_ENV. It would be helpful in the case
where a Rails application and Rack application are composed
together, while we want Rails app runs under development
and Rack app runs under none (if we don't want those default
middleware), and we don't really want to make RAILS_ENV
set to development and RACK_ENV to none because it might be
confusing. Note that Rails would also look into RACK_ENV.

Another reason for this is that only `rackup' would be
inserting those default middleware. Both `thin' and `puma'
would not do this, nor does Rack::Handler.get.run which is
used in Sinatra.

So using this option would make it work differently from
`rackup' but somehow more similar to `thin' or `puma'.

Discussion thread on the mailing list:
http://rubyforge.org/pipermail/mongrel-unicorn/2013-January/001675.html
---
 bin/unicorn    | 5 +++++
 lib/unicorn.rb | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/bin/unicorn b/bin/unicorn
index 9962b58..415d164 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -58,6 +58,11 @@ op = OptionParser.new("", 24, '  ') do |opts|
     ENV["RACK_ENV"] = e
   end
 
+  opts.on("-N", "--no-default-middleware",
+          "no default middleware even if RACK_ENV is development") do |e|
+    rackup_opts[:no_default_middleware] = true
+  end
+
   opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
     rackup_opts[:daemonize] = !!d
   end
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index d96ff91..f0ceffe 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -49,6 +49,8 @@ module Unicorn
 
       pp({ :inner_app => inner_app }) if $DEBUG
 
+      return inner_app if op[:no_default_middleware]
+
       # return value, matches rackup defaults based on env
       # Unicorn does not support persistent connections, but Rainbows!
       # and Zbatery both do.  Users accustomed to the Rack::Server default
-- 
1.8.1.1

_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply related	[relevance 5%]

* No middleware without touching RACK_ENV
@ 2013-01-25 10:52  3% Lin Jen-Shin (godfat)
  0 siblings, 0 replies; 5+ results
From: Lin Jen-Shin (godfat) @ 2013-01-25 10:52 UTC (permalink / raw)
  To: unicorn list

Hi,

This might be a bit silly, but finally I decided to bring this up.

We're running a Rails app along with another Rack app in
the same config.ru, and what I want to do is telling Unicorn
that we don't want any middleware which Unicorn might
insert with RACK_ENV=development and RACK_ENV=
deployment, because we're adding Rack::CommonLogger
and other middleware by ourselves, while we're using
RACK_ENV=development for Rails when developing.

That is, we want to use RACK_ENV=development for Rails
because that's how it used to be, but we also don't want
those additional middleware got inserted automatically.
This has no problem with RACK_ENV=production.

I know this is somehow a spec from Rack, but I guess I
don't like this behaviour. One workaround would be
providing a `after_app_load' hook, and we add this to
the bottom of config.ru:

  ENV['RACK_ENV_ORIGINAL'] = ENV['RACK_ENV']
  ENV['RACK_ENV'] = 'none'

and add this to the unicorn configuration file:

  after_app_load do |_|
    ENV['RACK_ENV'] = ENV['RACK_ENV_ORIGINAL']
  end

This is probably a stupid hack, but I wonder if after_app_load
hook would be useful for other cases?

Or if we could have an option to turn off this Rack behaviour
simulation, like:

    default_middleware false

That might be more straightforward for what we want. Oh but
it seems it's not that easy to add this. What about an option
for unicorn?

    unicorn -E development -N

or

    unicorn -E development --no-default-middleware

This would need to be applied to `rainbows' and `zbatery', too,
though. Patches below for consideration:
(Sorry if Gmail messed the format up, but from last time
I tried, it doesn't accept attachments :( What's the best way?
Links to raw patches?)

https://github.com/godfat/unicorn/pull/2

commit 95de5abf38a81a76af15476d4705713d2d644664
Author: Lin Jen-Shin <godfat@godfat.org>
Date:   Fri Jan 25 18:18:21 2013 +0800

    Add `after_app_load' hook.

    The hook would be called right after application is loaded.

diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 7651093..332bdbc 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -43,6 +43,9 @@ class Unicorn::Configurator
     :before_exec => lambda { |server|
         server.logger.info("forked child re-executing...")
       },
+    :after_app_load => lambda { |server|
+        server.logger.info("application loaded")
+      },
     :pid => nil,
     :preload_app => false,
     :check_client_connection => false,
@@ -171,6 +174,13 @@ class Unicorn::Configurator
     set_hook(:before_exec, block_given? ? block : args[0], 1)
   end

+  # sets the after_app_load hook to a given Proc object.  This
+  # Proc object will be called by the master process right
+  # after application loaded.
+  def after_app_load(*args, &block)
+    set_hook(:after_app_load, block_given? ? block : args[0], 1)
+  end
+
   # sets the timeout of worker processes to +seconds+.  Workers
   # handling the request/app.call/response cycle taking longer than
   # this time period will be forcibly killed (via SIGKILL).  This
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index aa98aeb..a3b30ee 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -14,6 +14,7 @@ class Unicorn::HttpServer
   # :stopdoc:
   attr_accessor :app, :request, :timeout, :worker_processes,
                 :before_fork, :after_fork, :before_exec,
+                :after_app_load,
                 :listener_opts, :preload_app,
                 :reexec_pid, :orig_app, :init_listeners,
                 :master_pid, :config, :ready_pipe, :user
@@ -716,6 +717,7 @@ class Unicorn::HttpServer
         Gem.refresh
       end
       self.app = app.call
+      config.after_app_load.call(self)
     end
   end






And --no-default-middleware
https://github.com/godfat/unicorn/pull/3

commit e3575db2a36e3ca2acda18bfee97bf95609a9860
Author: Lin Jen-Shin <godfat@godfat.org>
Date:   Fri Jan 25 18:38:52 2013 +0800

    Add -N or --no-default-middleware option.

    This would prevent Unicorn from adding default middleware,
    as if RACK_ENV is always none. (not development nor deployment)

    This should also apply to `rainbows' and `zbatery'.

diff --git a/bin/unicorn b/bin/unicorn
index 9962b58..415d164 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -58,6 +58,11 @@ op = OptionParser.new("", 24, '  ') do |opts|
     ENV["RACK_ENV"] = e
   end

+  opts.on("-N", "--no-default-middleware",
+          "no default middleware even if RACK_ENV is development") do |e|
+    rackup_opts[:no_default_middleware] = true
+  end
+
   opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
     rackup_opts[:daemonize] = !!d
   end
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index d96ff91..f0ceffe 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -49,6 +49,8 @@ module Unicorn

       pp({ :inner_app => inner_app }) if $DEBUG

+      return inner_app if op[:no_default_middleware]
+
       # return value, matches rackup defaults based on env
       # Unicorn does not support persistent connections, but Rainbows!
       # and Zbatery both do.  Users accustomed to the Rack::Server default
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply related	[relevance 3%]

Results 1-5 of 5 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2013-01-25 10:52  3% No middleware without touching RACK_ENV Lin Jen-Shin (godfat)
2013-01-29  3:21  5% [PATCH] Add -N or --no-default-middleware option Lin Jen-Shin
2013-01-29  3:52  6% ` Eric Wong
2013-01-29  4:02  6%   ` Eric Wong
2013-01-29  4:03  7%   ` Lin Jen-Shin (godfat)

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).