如何指示Capistrano 3加载我在远程主机上设置的shell环境变量?
我想指示Capistrano加载在远程服务器上定义的环境变量。 我怎样才能做到这一点?
似乎当我在.bashrc
文件中导出我的环境变量时,Capistrano不会考虑它们。 Capistrano似乎正在执行/usr/bin/env
来创建执行远程命令的环境,但这似乎并没有从.bashrc
加载环境变量。
我也告诉你,我也在使用rvm-capistrano
(以防它可能有所帮助)。
任何线索?
虽然这个问题已经超过六个月了,但我会留在这里以防万一有人面临同样的问题。
Capistrano实际上加载了.bashrc
。 但是在文件顶部附近你会发现:
# If not running interactively, don't do anything [ -z "$PS1" ] && return
如果您在该行之后进行任何export
,则Capistrano将无法访问。 解决方案只是将我的设置置于此之上,而Capistrano就是我想要的。
在这个GitHub问题上也注意到了这个解决方案。
Capistrano不加载.bashrc
因为它不是交互式shell。 据我记得虽然它确实加载了.bash_profile
但是你可能会有更好的运气使用它。
您可以通过发出以下命令将当前环境变量传递给使用ssh的远程执行:
env | ssh user@host remote_program
也从这里举了例子
on roles(:app), in: :sequence, wait: 5 do within "/opt/sites/example.com" do # commands in this block execute in the # directory: /opt/sites/example.com as :deploy do # commands in this block execute as the "deploy" user. with rails_env: :production do # commands in this block execute with the environment # variable RAILS_ENV=production rake "assets:precompile" runner "S3::Sync.notify" end end end end
看起来你可以使用set环境变量来执行。 因此,请阅读当前的环境变量并使用with
设置。
在Capistrano 3中set :default_env, { ... }
像这儿:
set :default_environment, { 'env_var1' => 'value1', 'env_var2' => 'value2' }
你可以参考这个: 上一篇文章..
- 在Capistrano部署之后,Rails资产没有编译
- 如何在capistrano中存储秘密变量
- Capistrano 3:在任务中使用服务器自定义变量
- Rails Capistrano 3 – 如何将production.log文件共享到Capistrano的共享文件夹中?
- Capistrano 3 SSHKit :: Runner :: ExecuteError:在host 代理上执行时发生exception无法使用请求的身份对数据进行签名
- Capistrano 3在目录中执行
- 如何通过capistrano 3运行自定义rake任务?
- Capistrano 3.0 – 现在如何安全地提示输入密码?
- 运行cron job`require’时出错:无法加载此类文件 – bundler / setup(LoadError)