Capistrano和环境变量 [英] Capistrano and environment variables

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

问题描述

我已经切换到使用环境变量进行配置,它的工作原理很好 - 除非我必须部署或者使用capistrano运行任务。



Capistrano 3似乎执行每个前缀为 / usr / bin / env 的命令删除我通过 .bashrc 设置的任何环境变量。



编辑做一些更多的reasearch,这可能不是问题,问题可能是因为capistrano执行为非登录,非交互式shell,并且不加载 .bashrc 的.bash_profile



当capistrano执行任务时,什么是确保环境变量设置的最佳方法?

解决方案

你可能最好看看 ENVIRONMENT VARIABLES SHELL VARIABLES 之间的差异



当您启动SSH时,您的应用程序将加载您的 .bashrc 文件中定义的SHELL变量。这些只存在于shell的生命中,因此,我们不使用它们与 ENV vars



<你可能会把 ENV vars放在:

  etc / environment 

像这样:

  export ENVIRONMENT_VAR = value 

这将使变量在整个系统,不只是在不同的shell会话中






更新



您是否尝试过



  set:default_env,{
'env_var1'=> 'value1',
'env_var2'=> 'value2'
}


I've switched to using environment variables for configuration and it works very well - except when I have to deploy or run tasks with capistrano.

Capistrano 3 seems to execute each command prefixed with /usr/bin/env which erases any environment variables I've set through .bashrc.

EDIT - on doing some more reasearch, this might not be the issue, the issue might be because capistrano executes as a non-login, non-interactive shell and does not load .bashrc or .bash_profile. Still stuck, though.

What would be the best way of making sure the environment vars are set when capistrano executes its tasks?

解决方案

You might be best looking at the difference between ENVIRONMENT VARIABLES and SHELL VARIABLES

When you fire SSH, your app will load the SHELL variables which are defined in your .bashrc file. These only exist for the life of the shell, and therefore, we don't use them as much as ENV vars

You may be better putting the ENV vars in:

/etc/environment

Like this:

export ENVIRONMENT_VAR=value

This will make the variables available throughout the system, not just in different shell sessions


Update

Have you tried

Capistrano: Can I set an environment variable for the whole cap session?

set :default_env, { 
  'env_var1' => 'value1',
  'env_var2' => 'value2'
}

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

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