* [PATCH] set RACK_ENV on startup
@ 2009-11-04 1:24 Wayne Larsen
2009-11-04 3:06 ` Eric Wong
0 siblings, 1 reply; 5+ messages in thread
From: Wayne Larsen @ 2009-11-04 1:24 UTC (permalink / raw)
To: mongrel-unicorn
Most stupid patch ever, but is there a reason not to set RACK_ENV on
startup with `unicorn`, as RAILS_ENV is set with `unicorn_rails`?
Thanks
Wayne
---
bin/unicorn | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/bin/unicorn b/bin/unicorn
index 0fed11e..9967f87 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -58,6 +58,7 @@ opts = OptionParser.new("", 24, ' ') do |opts|
opts.on("-E", "--env ENVIRONMENT",
"use ENVIRONMENT for defaults (default: development)") do |
e|
+ ENV['RACK_ENV'] = e
env = e
end
--
1.6.0.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] set RACK_ENV on startup
2009-11-04 1:24 [PATCH] set RACK_ENV on startup Wayne Larsen
@ 2009-11-04 3:06 ` Eric Wong
2009-11-04 3:51 ` Wayne Larsen
0 siblings, 1 reply; 5+ messages in thread
From: Eric Wong @ 2009-11-04 3:06 UTC (permalink / raw)
To: unicorn list
Wayne Larsen <wayne@larsen.st> wrote:
> Most stupid patch ever, but is there a reason not to set RACK_ENV on
> startup with `unicorn`, as RAILS_ENV is set with `unicorn_rails`?
Hi Wayne,
Does anything use/depend on it? `unicorn' is modeled after `rackup' and
I don't think it's a good idea to expose things if nothing uses it
(rackup does not set it, either).
RAILS_ENV is an accepted standard for Rails applications and there are
plenty of things that already depend on it.
--
Eric Wong
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] set RACK_ENV on startup
2009-11-04 3:06 ` Eric Wong
@ 2009-11-04 3:51 ` Wayne Larsen
2009-11-04 5:29 ` Eric Wong
0 siblings, 1 reply; 5+ messages in thread
From: Wayne Larsen @ 2009-11-04 3:51 UTC (permalink / raw)
To: unicorn list
On 2009-11-03, at 9:06 PM, Eric Wong wrote:
> Wayne Larsen <wayne@larsen.st> wrote:
>> Most stupid patch ever, but is there a reason not to set RACK_ENV on
>> startup with `unicorn`, as RAILS_ENV is set with `unicorn_rails`?
>
> Hi Wayne,
>
> Does anything use/depend on it? `unicorn' is modeled after `rackup'
> and
> I don't think it's a good idea to expose things if nothing uses it
> (rackup does not set it, either).
>
Passenger passes the RACK_ENV value to apps:
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#RackEnv
As does thin:
http://github.com/macournoyer/thin/blob/master/lib/thin/controllers/controller.rb#L169
Sinatra uses it to set its environment:
http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1013
As does Merb:
http://github.com/merb/merb/blob/master/merb-gen/lib/generators/templates/application/merb_stack/config.ru
> RAILS_ENV is an accepted standard for Rails applications and there are
> plenty of things that already depend on it.
>
It seems to me that RACK_ENV is a semi-standard. From a search of the
rack group, this has come up before (unanswered):
http://groups.google.com/group/rack-devel/browse_frm/thread/109241d9246f91ab/4a0d2f61a7851a6c?lnk=gst&q=RACK_ENV#4a0d2f61a7851a6c
or http://tinyurl.com/yl9re66
And this discussion:
http://groups.google.com/group/rack-devel/browse_frm/thread/822ce0551fbefa27/d52ea85fcb4e5a51?lnk=gst&q=RACK_ENV#d52ea85fcb4e5a51
also at http://tinyurl.com/yhssua2
where some suggested that it should be available in the rack
environment instead of as a global ENV variable.
It seems like the pragmatic answer would be to set it.
Wayne
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] set RACK_ENV on startup
2009-11-04 3:51 ` Wayne Larsen
@ 2009-11-04 5:29 ` Eric Wong
2009-11-04 17:13 ` Eric Wong
0 siblings, 1 reply; 5+ messages in thread
From: Eric Wong @ 2009-11-04 5:29 UTC (permalink / raw)
To: unicorn list
Wayne Larsen <wayne@larsen.st> wrote:
> On 2009-11-03, at 9:06 PM, Eric Wong wrote:
>> Wayne Larsen <wayne@larsen.st> wrote:
>>
>> Does anything use/depend on it? `unicorn' is modeled after `rackup'
>> and
>> I don't think it's a good idea to expose things if nothing uses it
>> (rackup does not set it, either).
>>
> Passenger passes the RACK_ENV value to apps:
> http://www.modrails.com/documentation/Users%20guide%20Nginx.html#RackEnv
>
> As does thin:
> http://github.com/macournoyer/thin/blob/master/lib/thin/controllers/controller.rb#L169
>
> Sinatra uses it to set its environment:
> http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1013
>
> As does Merb:
> http://github.com/merb/merb/blob/master/merb-gen/lib/generators/templates/application/merb_stack/config.ru
> It seems like the pragmatic answer would be to set it.
Agreed. Thanks for the research and links!
I've pushed out the following change:
>From c7f2242a53ceec6892bd72f0df771266d5193004 Mon Sep 17 00:00:00 2001
From: Wayne Larsen <wayne@larsen.st>
Date: Tue, 3 Nov 2009 21:12:47 -0800
Subject: [PATCH] bin/unicorn: set ENV["RACK_ENV"] on startup
Although not currently part of the Rack specification,
ENV["RACK_ENV"] is at least a de facto standard. Some of the
popular Rack servers (Thin, Passenger) and frameworks (Merb,
Sinatra) already set or use it.
ML-Ref: <C7A9411D-CD40-4DA4-9CB3-6AA959D2D127@larsen.st>
Acked-by: Eric Wong <normalperson@yhbt.net>
[ew: setenv always, not just on CLI + commit message]
---
bin/unicorn | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/bin/unicorn b/bin/unicorn
index 0fed11e..1916098 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -118,6 +118,8 @@ if config =~ /\.ru$/
end
end
+ENV['RACK_ENV'] = env
+
require 'pp' if $DEBUG
app = lambda do ||
--
Eric Wong
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] set RACK_ENV on startup
2009-11-04 5:29 ` Eric Wong
@ 2009-11-04 17:13 ` Eric Wong
0 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2009-11-04 17:13 UTC (permalink / raw)
To: unicorn list
Eric Wong <normalperson@yhbt.net> wrote:
> I've pushed out the following change:
Actually, I think I'll go with this:
>From ae2afbcc7dbac0af3256aa8b46afebf6e309bac0 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Wed, 4 Nov 2009 17:09:26 +0000
Subject: [PATCH] bin/unicorn: allow RACK_ENV to be passed from parent
This makes our RACK_ENV handling like our RAILS_ENV
handling for unicorn_rails, removing the redundant
local variable.
---
bin/unicorn | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/bin/unicorn b/bin/unicorn
index 1916098..225e819 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -3,7 +3,7 @@
require 'unicorn/launcher'
require 'optparse'
-env = "development"
+ENV["RACK_ENV"] ||= "development"
daemonize = false
listeners = []
options = { :listeners => listeners }
@@ -58,7 +58,7 @@ opts = OptionParser.new("", 24, ' ') do |opts|
opts.on("-E", "--env ENVIRONMENT",
"use ENVIRONMENT for defaults (default: development)") do |e|
- env = e
+ ENV["RACK_ENV"] = e
end
opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
@@ -118,8 +118,6 @@ if config =~ /\.ru$/
end
end
-ENV['RACK_ENV'] = env
-
require 'pp' if $DEBUG
app = lambda do ||
@@ -135,7 +133,7 @@ app = lambda do ||
Object.const_get(File.basename(config, '.rb').capitalize)
end
pp({ :inner_app => inner_app }) if $DEBUG
- case env
+ case ENV["RACK_ENV"]
when "development"
Rack::Builder.new do
use Rack::CommonLogger, $stderr
--
--
Eric Wong
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-11-04 17:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-04 1:24 [PATCH] set RACK_ENV on startup Wayne Larsen
2009-11-04 3:06 ` Eric Wong
2009-11-04 3:51 ` Wayne Larsen
2009-11-04 5:29 ` Eric Wong
2009-11-04 17:13 ` Eric Wong
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).