Heroku RACK_ENV says "development" on Thin, but "staging" on Unicorn
Asked Answered
C

2

5

I came across this behavior and was wondering if anyone else had seen it. I have a workaround so it's not a show-stopper.

I created a new app on Heroku with a Cedar stack. When demonstrating multiple environments I added the following config var:

heroku config:add RACK_ENV=staging --app appname

I visually verified that the environment var was set, then put the following route in my simple Sinatra example:

get '/?' do
  ENV['RACK_ENV']
end

When I tested locally on my laptop, I received the expected development.

When I pushed to Heroku and hit the same route on herokuapp.com I got development instead of staging.

I switched the web server from Thin to Unicorn through the Procfile and pushed the changes back up to Heroku.

Now when I hit the route, I get the expected staging.

Has anyone else seen this? My workaround on another project where I was running Thin was to key the environment off of the New Relic app name. (I didn't switch to Unicorn because I need New Relic to work and currently Cedar and New Relic and Unicorn work together).

Chronoscope answered 7/8, 2011 at 20:42 Comment(0)
O
14

I had the same problem with sinatra and thin on the cedar stack using heroku's example sinatra app. The RACK_ENV refuses to be set to anything but development. (Heroku seems to think that it's RACK_ENV is set, since running 'heroku config' displays the environment you set, however in the app it's always development).

The same app on the bamboo stack had no problems.

EDIT: I submitted a ticket to heroku about this and got a really quick response which fixed the bug for me:

QUOTE: It looks like there's a small bug in our default Procfile if you're using thin. Can you create a Procfile with the following in it?

web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT

Oratorio answered 29/10, 2011 at 0:14 Comment(2)
Man -- really glad I found this. This fixed my new relic integrationRomain
Thanks! But incredible that this hasn't been fixed by now.Heathenism
S
4

You can also set both your RACK_ENV and RAILS_ENV to staging using the Heroku gem ... then it works as expected. I think it may be a problem with Heroku.

Sedgewinn answered 17/2, 2012 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.