8

我正在尝试使用 Capistrano 3.0 将我的 Rails 应用程序部署到 EC2 实例中。我现在与运行“cap production deploy”或“cap production bundler:install”时出现的以下输出堆叠在一起。

DEBUG [5b379979] Running /usr/bin/env if test ! -d /var/www/app/current; then echo "Directory does not exist '/var/www/app/current'" 1>&2; false; fi on ec2-75-101-200-185.compute-1.amazonaws.com
DEBUG [5b379979] Command: if test ! -d /var/www/app/current; then echo "Directory does not exist '/var/www/app/current'" 1>&2; false; fi
DEBUG [5b379979] Finished in 2.285 seconds command successful.
 INFO [f15c9f08] Running /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/billtune/shared/bin --without development test on ec2-75-101-200-185.compute-1.amazonaws.com
DEBUG [f15c9f08] Command: cd /var/www/app/current && /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/app/shared/bin --without development test
DEBUG [f15c9f08]    /usr/bin/env: 
DEBUG [f15c9f08]    bundle
DEBUG [f15c9f08]    : No such file or directory
DEBUG [f15c9f08]    
cap aborted!
bundle stdout: Nothing written
bundle stderr: Nothing written
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/command.rb:94:in `exit_status='
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:147:in `block (2 levels) in _execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:149:in `block in _execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:20:in `block (4 levels) in <top (required)>'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/abstract.rb:81:in `within'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:19:in `block (3 levels) in <top (required)>'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `run'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => bundler:install

当 ssh-ing 进入服务器并运行相同的命令(“cd /var/www/app/current && /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/ www/app/shared/bundle --deployment --verbose --binstubs /var/www/app/shared/bin --without development test") 一切似乎都很好......

对此感到非常绝望......谢谢!

4

7 回答 7

5

线条

DEBUG [f15c9f08] Command: cd /var/www/app/current && /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/app/shared/bin --without development test
DEBUG [f15c9f08]    /usr/bin/env: 
DEBUG [f15c9f08]    bundle
DEBUG [f15c9f08]    : No such file or directory
DEBUG [f15c9f08]    

指示未找到或未安装捆绑程序。Capistrano(如此处记录的http://www.capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/)以非登录方式运行,非交互式外壳

我猜这个 bundler 安装在一个特殊的路径中,或者你使用的是 rvm、chruby 或 rbenv。由于 Capistrano 正在使用非登录、非交互式会话,这些东西并没有像当你 SSH 进入盒子时那样被初始化。

解决方案是使用capistrano-{rvm,chruby,rbenv}适合您环境的 gem,如Capfile.

如果您没有使用这些版本管理器之一,请尝试以下操作:

ssh me@theserver 'which bundler'

可能你不会看到任何输出(更多关于为什么在上面的链接中),解决这个问题,Capistrano 就会工作。

于 2013-10-17T08:36:47.263 回答
3

问题确实出在非交互式 shell上。

最终我不得不将以下行添加到.bashrc

source ~/.rvm/scripts/rvm

万一其他人遇到类似的问题,我会补充一点,我还必须映射rake命令,以便它能够正常工作。必须将以下行添加到我的deploy.rb文件中:

SSHKit.config.command_map[:rake] = "bundle exec rake"
于 2013-10-20T14:41:30.507 回答
1

你最好使用 capistrano-rbenv gem 来管理你的 ror env

  1. 添加gem 'capistrano-rbenv', '~> 2.0' to your宝石文件
  2. require 'capistrano/rbenv'在您的 capfile 中取消注释;如果capistrano/bundler评论,也取消评论
  3. set :rbenv_ruby, '2.0.0-p247'在部署文件中设置 rbenv_ruby 变量

然后一切就绪!

于 2013-12-11T09:32:22.400 回答
1

我回答这个问题有点晚了,但它可能会对像我这样的用户有所帮助。

如果您正在使用,则通过添加以下行来rbenv设置您的默认环境rbenvdeploy.rb

set :default_env, { path: "~/.rbenv/shims:~/.rbenv/bin:$PATH" }

于 2015-10-20T09:37:46.167 回答
0

我能够通过将以下代码添加到 ~/.bashrc 来解决这个问题:

export RBENV_ROOT="${HOME}/.rbenv"

if [ -d "${RBENV_ROOT}" ]; then
  export PATH="${RBENV_ROOT}/bin:${PATH}"
  eval "$(rbenv init -)"
fi
于 2015-01-27T15:36:00.617 回答
0

系统bundle中缺少可执行文件,或者 shell 不知道它的 PATH。

检查以下测试:

系统可以找到perl可执行文件:

# /usr/bin/env perl
^C   << I did CTRL+C as perl was expecitng me to put some code

现在,我的系统找不到perlyo可执行文件并抛出错误:

# /usr/bin/env perlyo
/usr/bin/env: perlyo: No such file or directory

上面的错误类似于你得到的错误/usr/bin/env bundle是:

DEBUG [f15c9f08]    /usr/bin/env: 
DEBUG [f15c9f08]    bundle
DEBUG [f15c9f08]    : No such file or directory 

bundle通过运行以下命令检查系统是否知道:

# which bundle
# whereis bundle

如果使用上述命令找不到,则检查bundle系统上是否完全存在,如下所示:

# updatedb
# locate bundle

如果您找到bundle,则相应地添加它path,以便您的 shell 可以识别它。

希望这可以帮助。

于 2013-10-17T09:11:14.747 回答
0

As @zpieslak said:

add this in ~/.bashrc:

if [ -d "${RBENV_ROOT}" ]; then
  export PATH="${RBENV_ROOT}/bin:${PATH}"
  eval "$(rbenv init -)"
fi

Before this line:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
于 2015-11-12T12:48:25.287 回答