ruby-on-rails Capistrano捆绑器:安装失败

yeotifhr  于 2023-02-17  发布在  Ruby
关注(0)|答案(7)|浏览(167)

我正在尝试使用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)时,一切似乎都正常。

db2dz4w8

db2dz4w81#

台词

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]

指示未找到或未安装bundler。Capistrano(如本文http://www.capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/所述)在非登录、非交互式shell中运行。
我猜bundler安装在一个特殊的路径中,或者您使用的是rvm、chruby或rbenv,并且这些东西没有像您SSH到机器中时那样初始化,因为Capistrano使用的是非登录、非交互式会话。
解决方案是使用capistrano-{rvm,chruby,rbenv} gem,它适合您的环境,如Capfile中所述。
如果您没有使用这些版本管理器之一,请尝试以下操作:

ssh me@theserver 'which bundler'

也许你会看到没有输出(更多关于为什么在上面的链接),解决这个问题,卡皮斯特拉诺将工作。

eimct9ow

eimct9ow2#

问题确实出在 * 非交互式shell* 上。
最后,我不得不在.bashrc中添加以下行:

source ~/.rvm/scripts/rvm

如果其他人遇到类似的问题,我将补充说,我还必须Maprake命令,以便它可以正常工作。必须添加以下行到我的deploy.rb文件:

SSHKit.config.command_map[:rake] = "bundle exec rake"
hpcdzsge

hpcdzsge3#

你最好使用capistrano-rbenv gem来管理你的ror环境
1.添加gem 'capistrano-rbenv', '~> 2.0' to your宝石文件
1.取消注解capfile中的require 'capistrano/rbenv';如果capistrano/bundler已注解,则也取消注解
1.在部署文件中设置rbenv_ruby变量set :rbenv_ruby, '2.0.0-p247'
那就都准备好了!

h5qlskok

h5qlskok4#

我可以通过在~/.bashrc中添加以下代码来解决这个问题:

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

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

n3schb8v5#

我回答这个问题有点晚了,但它可能会帮助一些像我这样的用户。
如果您使用的是rbenv,则通过在deploy.rb中的下面一行中添加以下内容来设置rbenv的默认环境
set :default_env, { path: "~/.rbenv/shims:~/.rbenv/bin:$PATH" }

kx7yvsdv

kx7yvsdv6#

系统中缺少bundle可执行文件,或者shell不知道其路径。
检查以下测试:
系统可以找到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能够识别它。
希望这个有用。

gc0ot86w

gc0ot86w7#

正如@zpieslak所说:
在~/.bashrc中添加以下内容:

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

此行之前:

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

相关问题