Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Jul 09, 2015 3:38 pm 
Offline
Newbie

Joined: Thu Jul 09, 2015 3:04 pm
Posts: 2
This may be a long shot, but I am struggling to figure out why I can't get this to work. I have just set up a Linode with Ubuntu 14 and the latest passenger, nginx, rails and rbenv, installed as the deploy user. I used capistrano to deploy an app to this server, creating symlinks to secrets.yml. Secrets.yml contains the following for running in production:

secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_token: <%= ENV["SECRET_TOKEN"] %>

The rbenv-vars plugin is also installed, and I created .rbenv-vars file in appname/current/ which contains:

SECRET_KEY_BASE=<inserted secret key string here>
SECRET_TOKEN=<inserted secret token string here>

Theoretically, this should work, but it doesn't. When I enter the keys directly in secrets.yml, the app works. But when I reference .rbenv-vars as above, I get an error that the key base and token can't be found. Since rbenv was installed in the home of the deploy user, I recursively set the group of .rbenv to www-data. I have checked that running rbenv vars in appname/current returns the following:

export SECRET_KEY_BASE='<the appropriate secret key base from .rbenv-vars>'
export SECRET_TOKEN='<the appropriate secret token from .rbenv-vars'

I can't figure out what I'm doing wrong and why passenger can't find these keys. Anyone on here have any idea what I didn't do right? Thanks so much for your help.

Robert


Top
   
PostPosted: Thu Jul 09, 2015 5:56 pm 
Offline
Senior Member

Joined: Thu Feb 20, 2014 5:06 pm
Posts: 58
Rbenv works by adding a Bash startup script to /etc/profile.d/, which contains the code that sets up your $PATH and all the other niceties. This script (and all others in /etc/profile.d) is only loaded by Bash when Bash is invoked as a login shell, which is how you normally use Bash. However, the "nginx" process is launched as part of the init system. If the init system uses Bash at all (which is the case for System V scripts, but not systemd), then Bash isn't going to be invoked as a login shell, so those Rbenv files aren't going to read. Hence, the rbenv-vars code isn't going to be executed, and the environment variables aren't going to be set. Since passenger is spawned by nginx, it's not going to see those environment variables either.

The Passenger docs have a little more info on this: https://www.phusionpassenger.com/docume ... _variables

TL;DR: Environment variables are confusing


Top
   
PostPosted: Thu Jul 09, 2015 10:04 pm 
Offline
Newbie

Joined: Thu Jul 09, 2015 3:04 pm
Posts: 2
Well, I thought I had that base covered by adding env PATH; to the beginning of nginx.conf. I used that to solve a problem where passenger couldn't find a javascript runtime even though nodejs was installed. Thanks for pointing out that the correct way to do this now (as of passenger v5) is to use passenger_env_var instead (per passenger docs). By adding:

passenger_env_var PATH <entire PATH environment variable from deploy user bash shell>;

to nginx.conf in the http section, passenger now uses nodejs and rbenv. I don't need env PATH; in nginx.conf at all. Thanks for helping me figure this out.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group