我读过关于登录/非登录、交互式/非交互式 shell 的精彩解释 http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/ .但我无处可寻,如何在特定的 shell 中运行 capistrano 3。我尝试过以下选项:
set :pty, true # non-login, interactive but does not load .bashrc
set :default_shell, '/bin/bash --login'
set :shell, '/bin/bash --login'
但没有任何帮助。谢谢。
最佳答案
我知道这是一个很老的问题,但下面显示了如何为 capistrano 打开 SSHKit 类并启用登录 shell。
# backend/sshkit.rb
module SSHKit
class CommandMap
class SuffixProvider
def initialize
@storage = CommandHash.new
end
def [](command)
@storage[command] ||= []
@storage[command]
end
def to_s(command)
self.[](command).join(" ")
end
end
def [](command)
cmd = []
if prefix[command].any?
prefixes = prefix[command].map{ |prefix| prefix.respond_to?(:call) ? prefix.call : prefix }
cmd.push(prefixes.join(" "))
end
cmd.push(@map[command])
cmd.join(" ")
end
def suffix
@suffix ||= SuffixProvider.new
end
end
class Command
def to_s
[SSHKit.config.command_map[command.to_sym], *Array(args), SSHKit.config.command_map.suffix.to_s(command.to_sym)].compact.join(' ')
end
end
end
现在您可以定义 SSHKit 命令映射来为特定命令启用 bash --login
。
SSHKit.config.command_map[:rvm].prefix("bash --login '")
SSHKit.config.command_map[:rvm].suffix("'")
现在你可以像下面这样使用:rvm
命令了。
execute :rvm, :use, '2.2.2', '--install'
# => bash --login 'rvm use 2.2.2 --install'
我写了一个blog post这进一步解释了这一点。但是,我建议您仅在必须需要时才使用登录 shell。
关于ruby-on-rails - Capistrano 3 使用登录 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23388892/