Capistrano:我可以为整个上限会话设置环境变量吗? [英] Capistrano: Can I set an environment variable for the whole cap session?

查看:147
本文介绍了Capistrano:我可以为整个上限会话设置环境变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了标准Ruby和Ruby Enterprise的分段服务器。由于标准的Ruby拒绝安装一个关键的宝石,我需要设置$ PATH,以便ruby / gem / rake / etc。总是参考REE版本。因为我使用Capistrano来部署到我们的机器上,我需要在Capistrano中进行。



如何设置一个环境变量一次,并持续在Capistrano会话中?



1)在bashrc文件中很容易,但是Capistrano不会读取bashrc文件。



2)我将使用Capistrano的

  default_environment ['PATH'] ='Whatever'

但是Capistrano使用这些环境变量,如

  env PATH =无论命令参数... 

每当另外一个shell在可执行文件中被转发到env之前就重新丢失。喜欢当你使用sudo。这很重要:

  [holt @ Michaela trunk] $ env VAR = hello ruby​​ -e放置ENV ['VAR' ]
hello
[holt @ Michaela trunk] $ env VAR = hello sudo ruby​​ -e放置ENV ['VAR']
nil

3)我不能使用bash export命令,因为这些都丢了 - Capistrano似乎为每个命令启动一个新的shell或者类似的东西),那也是丢了:

  cap> export MYVAR = 12 
[建立连接到xxx.xxx.xxx.xxx]
cap> echo $ MYVAR
** [out :: xxx.xxx.xxx.xxx]
cap>

4)我试图搞砸Capistrano的:shell和:pty选项(和组合与其他方法),但没有运气,或者。



所以 - 这是正确的方法?这似乎是这样的基本任务应该是一个非常简单的方法来完成,但我没有想法。任何人?



提前感谢

解决方案

同样的问题,但我认为这个解决方案是更好的:

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

这对我来说就像一个魅力。


I've got a staging server with both standard Ruby and Ruby Enterprise installed. As standard Ruby refuses to install a critical gem, I need to set $PATH so that ruby/gem/rake/etc. always refer to the REE versions. And since I use Capistrano to deploy to our machines, I need to do it in Capistrano.

How can I set an environment variable once, and have it persist throughout the Capistrano session?

1) It's easy to do in bashrc files, but Capistrano doesn't read bashrc files.

2) I'd use Capistrano's

default_environment['PATH'] = 'Whatever'

but Capistrano uses these environment variables like

env PATH=Whatever command arg ...

and they're lost whenever another shell is spun up within the executable passed to env. Like when you use sudo. Which is kinda important:

[holt@Michaela trunk]$ env VAR=hello ruby -e "puts ENV['VAR']"
hello
[holt@Michaela trunk]$ env VAR=hello sudo ruby -e "puts ENV['VAR']"
nil

3) And I can't use the bash export command, as these are lost too - Capistrano seems to start up a new shell for each command (or something like that), and that's lost, too:

cap> export MYVAR=12
[establishing connection(s) to xxx.xxx.xxx.xxx]
cap> echo $MYVAR
 ** [out :: xxx.xxx.xxx.xxx] 
cap> 

4) I've tried messing with Capistrano's :shell and :pty options as well (and in combination with the other approaches), but no luck there, either.

So - what's the right way to do this? This seems like such a basic task that there should be a really simple way to accomplish it, but I'm out of ideas. Anyone?

Thanks in advance!

解决方案

I have the exactly same problem, but I think this solution is better:

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

This works for me like a charm.

这篇关于Capistrano:我可以为整个上限会话设置环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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