[PATCH] set RACK_ENV on startup

Eric Wong normalperson at yhbt.net
Wed Nov 4 00:29:08 EST 2009


Wayne Larsen <wayne at larsen.st> wrote:
> On 2009-11-03, at 9:06 PM, Eric Wong wrote:
>> Wayne Larsen <wayne at 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 at 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 at larsen.st>
Acked-by: Eric Wong <normalperson at 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


More information about the mongrel-unicorn mailing list