wildabeast
wildabeast

Reputation: 1832

Rails app not loading new environment variable added to /etc/environment

I'm trying to add an environment variable to use in my Rails App. Currently, our app uses several environment variables defined in /etc/environment. They work fine. So I've added a new variable to /etc/environment (and rebooted for the hell of it). But when I try to access the new variable, its undefined. Printing out ENV.inspect shows all the original variables, but not my newly added one. Why oh why?

Running Apache 2 / Passenger 4 / Rails 4. Recently upgraded from Passenger 2 / Rails 3 if its significant.

Edit

Turns out the ones I thought 'work fine' don't work either (they're redefined in my Rails app). So none of the variables in /etc/environment are loaded into the app. Not sure why I thought that system worked, but it doesn't.

Upvotes: 5

Views: 1044

Answers (2)

Richard Peck
Richard Peck

Reputation: 76774

ENV

Upgrading from Rails 3 - Rails 4 should not be a major concern for the ENV variables, unless the way Rails processes them will have changed.

We use the following:

enter image description here

This works for us with Rails 4, Ubuntu 12.04, Passenger, Apache 2

--

The problem you may have is that your Rails application has not updated since you added the new variables.

When you run a Rails app, it essentially loads an "instance" of the application, and then keeps loading it somehow. I'm not totally sure how it works, but I do know the likes of Passenger essentially "cache" a rails app whilst in production

This means if you're adding new Environment variables, perhaps the likes of Passenger has made it so the Rails application has not been updated? If this is the case you may wish to use the touch tmp/restart.txt command:

enter image description here

Upvotes: 1

Maurício Linhares
Maurício Linhares

Reputation: 40313

Might not be good news to you, but you have to reboot the instance to see it happen (or check the other tricks at that question).

You can also use SetEnv at your Apache config and just restarting apache itself will make your app see the new values.

Upvotes: 2

Related Questions