使用 Capistrano 的 运行 捆绑包问题

Issue with running bundle using Capistrano

我在其他几个 questions/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。具体来说,它是一个 Rails 4.2.0 应用程序,带有 gem capistrano-railscapistrano-rvm.

我有一个非常标准的 config/unicorn.rb 文件,这是我在登录服务器时启动 unicorn 的方式。我首先用以下命令杀死当前的 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 配合得很好,例如预编译资产、迁移我的数据库等。我添加的自定义任务出现了错误.

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

仔细查看 Capistrano 的输出。 bundle assets:precompile makes 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.

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