【问题标题】:Interactive Shell with Mina and Capistrano带有 Mina 和 Capistrano 的交互式 Shell
【发布时间】:2016-10-21 18:28:16
【问题描述】:

Capistrano Doc 说

http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/#

ssh me@remote "[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'"
Interactive
me@localhost $ ssh me@remote "shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'"
Not login shell

Capistrano 声明该命令在“交互式和非登录 shell”中的 ssh me@remote 上运行。很好,但这是我的观点。

我所做的是,我在我的 .bashrc 中添加了一个看起来像这样的简单测试

echo $-
# If not running interactively, don't do anything
case $- in
   *i*) echo 'Interactive';;
     *) echo 'Non Interactive';;
esac

现在,我没有用双引号 (") 将 Capistrano 示例包裹在单引号 (') 中,因为我觉得双引号 扩展了当前 shell 的表达式(在我的情况是我的笔记本电脑tty终端)

结果:

ssh me@remote '[[ $- == *i* ]] && echo "Interactive" || echo "Not interactive"'
hBc
Non Interactive
Not interactive

Question 1: - Capistrano 文档正确吗?。看我上面的结果,命令似乎是通过 ssh run in non-interactive and non-login shell 运行的。

Question 2: 如果我是正确的(就问题 1 而言)我如何在交互式 shell 中运行命令?我的印象是-t 选项会强制tty 分配,这会有所帮助。但这也无济于事。

ssh me@remote -t '[[ $- == *i* ]] && echo "Interactive" || echo "Not interactive"'
hBc
Non Interactive
Not interactive
Connection to remote closed. 

Question 3: 现在回答原始问题。我正在使用 Mina 进行部署。现在,在 mina 部署期间,rvm 永远不会加载。

我的 bash 在 bashrc

中有以下定义的原因
# bashrc
case $- in #when mina load bashrc it's a non-interactive shell.
    *i*) ;;
      *) return;;
esac

source ~/.rvm/scripts/rvm  # this is never gets executed

Question 4(a) 人们如何解决这个问题?当然移动文件顶部的 rvm 源负载会有所帮助,但我正在寻找不同的答案。

Question 4 b:Capistrano 和 Mina 如何处理它。如果可以?

【问题讨论】:

  • 链接的文档看起来是正确的:“默认情况下,Capistrano 始终分配一个非登录、非交互式 shell。”

标签: bash shell ssh capistrano3 mina


【解决方案1】:

我不使用 RVM,但我会快速回答您的问题:

Q1:除非我遗漏了另一份文档,否则您引用错误。它说:

默认情况下,Capistrano 始终分配一个非登录、非交互式 shell。

Q2:你不能/不应该。 Capistrano 部署应该完全无人值守,在这种情况下不需要交互式外壳。

Q3:这是我不确定的地方,因为我只使用了 rbenv。不过我会试一试。使用https://github.com/capistrano/rvm 设置 RVM。一旦你有了它,如果你有一个除了这里列出的命令之外的命令:https://github.com/capistrano/rvm/blob/master/lib/capistrano/tasks/rvm.rake#L53,使用append :rvm_map_bins, 'nameofexecutable' 使 RVM 应用于你的命令。

Q4a/b:见 Q3。

猜你喜欢
  • 1970-01-01
  • 2013-04-16
  • 1970-01-01
  • 2016-02-17
  • 2013-08-13
  • 2017-07-15
  • 2021-07-14
  • 2011-11-19
  • 2014-08-07
相关资源
最近更新 更多