[PATCH] set RACK_ENV on startup

Eric Wong normalperson at yhbt.net
Wed Nov 4 12:13:55 EST 2009


Eric Wong <normalperson at 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 at 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


More information about the mongrel-unicorn mailing list