AWS OpsWorks 环境变量不起作用 [英] AWS OpsWorks Environment variables not working

查看:43
本文介绍了AWS OpsWorks 环境变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Ubuntu 14.04 LTS 64 位 Rails 应用程序,但无法访问我的应用程序环境变量.

I am running Ubuntu 14.04 LTS 64 bit Rails Application and I am unable to access my App environment variables.

在 OpsWorks App 面板中,我设置了环境变量,例如:

In OpsWorks App panel, I set my environment variables, say:

MYKEY: 1234

然后我再次保存并部署我的应用程序以使这些可见.

Then I save and deploy my app again to make these visible.

在我的 Rails 应用程序或 Rails 控制台中,我得到了 nil:

In my Rails app, or the rails console I get nil:

$ bundle exec rails c production
>ENV["MYKEY"]
=> nil

我尝试重新启动服务器.我不确定我缺少什么,我一直在其他服务中使用环境变量.

I have tried restarting the server. I'm not sure what I am missing, I have been using environment variables in other services.

我怎样才能追踪这些应该在哪里设置?

How can I trace where these should be set?

推荐答案

OpsWorks 将环境变量存储在不同的位置,具体取决于您部署的应用程序类型.在 Rails/Passenger 上,它们应该保存在 Apache 配置文件 #{your_app_name}.conf 中.(来源)

OpsWorks stores environmental variables in different places depending on what kind of app you're deploying. On Rails / Passenger they should be saved in the Apache config file #{your_app_name}.conf. (Source)

这意味着它们在您的普通 shell 环境中不可用.

This means they aren't available in your normal shell environment.

我知道 Node.js 配方将所有内容存储在 /srv/www/#{app_name}/shared/app.env 文件中...运行节点服务器.这个实现细节也意味着你可以编写 shell 脚本来获取 app.env 文件,然后调用一些 Node 脚本或其他东西.

I know the Node.js recipes stored everything in an /srv/www/#{app_name}/shared/app.env file... which is then sourced to pull in the environment to run the Node server. This implementation detail also meant you could write shell scripts that sourced that app.env file, then called some Node script or whatever.

当然,Rails 不是 Node.我不知道环境变量是否也存储在其他地方:快速浏览 OpsWorks 说明书中的 Rails 配方没有发现任何明显的东西,但也许我错过了一些东西.

Of course, Rails isn't Node. I have no idea if the environmental variables are also stored somewhere else or not: a quick look at the Rails recipes in the OpsWorks cookbooks didn't find anything obvious, but maybe I missed something.

根据您在 OpsWorks 说明书中进行的修改量,您可以创建一个执行以下操作的部署配方:

Depending on the amount of modifications you have going on in your OpsWorks cookbook, you could create a deploy recipe that does something like this:

application_environment_file 做用户部署[:用户]组部署[:组]路径 ::File.join(deploy[:deploy_to], 共享")environment_variables 部署[:environment_variables]结尾

(可能调整路径)

然后运行您的控制台,当您通过 SSH 连接到服务器时,执行类似的操作

Then to run your console, when you're SSHed into the server, do something like

sudo source/srv/www/my_app_name/shared/app.env;bundle exec rails console -e production 或其他.

这篇关于AWS OpsWorks 环境变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆