默认情况下使用bash --login和capistrano 3 + sshkit + rvm

时间:2014-01-26 07:18:23

标签: shell rvm .bash-profile capistrano3 sshkit

我有以下cap3任务

task :gemset do
  on roles(:all) do
    if remote_dir_exists?(".rvm")
      execute :rvm, :gemset, :use, "#{ Configs.rvm.ruby }@#{ Configs.rvm.gemset } --create"
    else
      info "RVM not installed"
    end
  end
end 

用于设置

rvm:
  ruby:   ruby-2.0.0-p247
  gemset: cap3

它应该在我的服务器上按照命令

执行
rvm gemset use ruby-2.0.0-p247@cap3 --create

但它给了我

DEBUG [9bd5fc11]  RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [9bd5fc11]
DEBUG [9bd5fc11]  You need to change your terminal emulator preferences to allow login shell.
DEBUG [9bd5fc11]  Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [9bd5fc11]  Please visit https://rvm.io/integration/gnome-terminal/ for a example.

解决了
SSHKit.config.command_map.prefix[:rvm].push("source .bash_profile &&")

现在我的任务看起来像这样

task :gemset do
  on roles(:all) do
    if remote_dir_exists?(".rvm")
      SSHKit.config.command_map.prefix[:rvm].push("source .bash_profile &&")
      execute :rvm, :gemset, :use, "#{ Configs.rvm.ruby }@#{ Configs.rvm.gemset } --create"
    else
      info "RVM not installed"
    end
  end
end   

在capistrano 2中,我有以下设置

default_run_options[:shell] = "/bin/bash --login"

但是在cap3中它不起作用

我尝试使用

set :pty, true
set :shell, '/bin/bash --login'
set :default_shell, '/bin/bash --login'

但是在cap3中它也不起作用

如何在没有SSHkit.config挂钩的情况下解决cap3中的 bash --login 问题?

1 个答案:

答案 0 :(得分:1)

你不能在脚本中使用rvm use - 除非你像使用prefix一样来源rvm,

但您可以在脚本中使用rvm ... do ...而无需采购:

execute :rvm, "#{ Configs.rvm.ruby }@#{ Configs.rvm.gemset }", "--create", :do, :true