To use bash --login by default with capistrano 3 + sshkit + rvm

给你一囗甜甜゛ 提交于 2019-12-08 02:18:20

问题


I have following cap3 task

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 

for settings

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

it should execute on my server following command

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

but it gives to me

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.

It was solved with

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

Now my task looks like this

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   

In capistrano 2 for this I had following setting

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

But in cap3 it doesn't work

I try to use

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

But in cap3 it doesn't work too

How can I solve bash --login problem in cap3 without SSHkit.config hook?


回答1:


you can not use rvm use from scripts - unless you source rvm first like you did with the prefix,

but you can use rvm ... do ... in scripts without sourcing:

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


来源:https://stackoverflow.com/questions/21360824/to-use-bash-login-by-default-with-capistrano-3-sshkit-rvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!