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

2019-05-19 17:37发布

问题:

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