【问题标题】:Issue with running bundle using Capistrano使用 Capistrano 运行捆绑包的问题
【发布时间】:2015-03-01 19:42:52
【问题描述】:

我已经在其他几个问题/Github 问题中看到了这个问题,但他们未能提供足够的信息来解决问题。

错误:

bash: bundle: command not found

SSHKit::Runner::ExecuteError: Exception while executing as my-user@my-IP-address: cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production exit status: 127

cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production stdout: Nothing written
cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production stderr: bash: bundle: command not found

我在我的 rails 应用上使用了最新版本的 Capistrano。具体来说,它是带有宝石capistrano-railscapistrano-rvm 的Rails 4.2.0 应用程序。

我有一个非常标准的config/unicorn.rb 文件,这是我在登录服务器时启动独角兽的方式。我首先杀死当前的PID:

kill -9 PID

然后我开始独角兽:

bundle exec unicorn -D -c /path-to-my/config/unicorn.rb -E production

这很好用,但显然我需要 capistrano 来做到这一点,所以我的 deploy.rb 文件中基本上有这些任务,但是我得到了上面提到的错误。这是我在deploy.rb 中的两个任务:

namespace :deploy do
  namespace :unicorn do
    task :restart do
      on roles(:app), in: :sequence, wait: 5 do
        execute "kill -s USR2 `cat /path-to-my/tmp/pids/app-name.pid`"
      end
    end

    desc 'Start unicorn' 
    task :start do
      on roles(:app), in: :sequence, wait: 5 do
        execute "cd #{current_path} ; bundle exec unicorn -D -c config/unicorn.rb -E production"
      end
    end
  end
end

我有一个类似的任务来重新启动 DelayedJob,这会引发相同的错误。命令是execute "cd #{current_path} ; RAILS_ENV=production bin/delayed_job -n2 restart"。就像我上面提到的,当使用我的用户(我用于 Capistrano 的同一用户)登录服务器时,所有这些任务都按预期工作。

其他所有内置任务都非常适合 Capistrano,例如预编译资产、迁移我的数据库等。这是我添加的自定义任务导致错误。

如果我可以添加任何内容来帮助解决问题,请告诉我。

【问题讨论】:

  • 你在服务器上使用的是 rvm 还是 rbenv?

标签: ruby-on-rails ruby-on-rails-4 capistrano unicorn


【解决方案1】:

仔细查看 Capistrano 的输出。 bundle assets:precompilemakes initialization of required ruby version等命令:

cd /<app path>/20150301211440 && ( RAILS_ENV=staging /usr/local/rvm/bin/rvm 2.1.5 do bundle exec rake assets:precompile )

好像你不这样做。因此,您可能默认使用系统 ruby​​,但它没有 bundler gem。

尝试在你的命令中指定 ruby​​ 版本使用 RVM。我认为它应该可以解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 2011-11-10
    • 2019-06-27
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多