Opsworks Rails Console Environment
Asked Answered
C

4

5

I am trying to run a rails console in amazon opsworks, I have tried:

sudo rails console -e production
sudo rails console production
RAILS_ENV=production sudo rails console
RAILS_ENV=production RACK_ENV=production sudo rails console

With each of those commands the console is spinning up in the development environment. What do I need to do to get this console started in the environment of my choosing?

Carlyncarlynn answered 1/7, 2013 at 19:34 Comment(0)
R
3

Assuming you are ssh'd into the instance.

$ cd /srv/www/yourapplication/current

$ sudo bundle exec rails console

Richmond answered 12/12, 2014 at 13:25 Comment(0)
G
17
sudo su deploy  # switch to the app user
cd /srv/www/myapp/current  # your deploy dir might be different (check logs if unsure)
RAILS_ENV=production bundle exec rails console
Gaffe answered 12/8, 2013 at 14:26 Comment(3)
Doesn't seem to work. I get an error about the environment variables being missing.Bergeron
@MattGibson sorry I haven't used the environment variable support. The cookbooks just write them into the unicorn.conf file so I'm not sure there's an elegant way to reuse them from there.Gaffe
@MattGibson See my answer, which adds -E to the sudo command. That should load the environment variables.Staffer
R
3

Assuming you are ssh'd into the instance.

$ cd /srv/www/yourapplication/current

$ sudo bundle exec rails console

Richmond answered 12/12, 2014 at 13:25 Comment(0)
S
0

Solution 1 (faster): You can add environment variables from .env(.environment)-file with this gem https://github.com/bkeepers/dotenv. You have to write down all keys and values in this file which you need to load.

Solution 2 (better): Do it like described here: http://dev.mikamai.com/post/90567083464/use-the-env-luke-aka-simulate-the-env-in

Sexennial answered 18/6, 2015 at 13:16 Comment(0)
S
0

If you'd prefer to load environment variables without running it as root and without adding dotenv to your Gemfile:

$ cd /srv/www/<NAME_OF_YOUR_APP>/current
$ sudo -u deploy -E bundle exec rails console production
Staffer answered 18/7, 2018 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.