使用 Capistrano 3 的 Cron 作业以及每当 gem 时找不到 Gemfile

Gemfile not found using Cron job with Capistrano 3 and whenever gem

Cron 作业在我的电脑上运行良好。但是当我使用 capistrano 将它部署到服务器时。 cron.log 文件显示它正在寻找服务器上不存在的版本我该如何解决这个问题。有什么想法...?

/home/deployer/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/bundler-1.7.2/lib/bundler/definition.rb:22:in `build': /home/deployer/apps/production_app/releases/20140906112257/Gemfile not found (Bundler::GemfileNotFound)
    from 

当我 运行 crontab -e 命令显示正确的版本时

# Begin Whenever generated tasks for: production_app
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /home/deployer/apps/production_app/releases/20150504102922 && bin/rails runner -e production '\''Vehicle.check_not_responding'\'' >> /home/deployer/apps/production_app/releases/20150504102922/log/cron.log 2>&1'

* * * * * /bin/bash -l -c 'cd /home/deployer/apps/production_app/releases/20150504102922 && bin/rails runner -e production '\''SmsDetail.send_sms'\'' >> /home/deployer/apps/production_app/releases/20150504102922/log/cron.log 2>&1'

# End Whenever generated tasks for: production_app

我该如何解决这个问题...?

我前段时间遇到了同样的问题。事实证明,当 cron 尝试 运行 任务时,变量 BUNDLE_GEMFILE 未定义。所以你需要在 schedule.rb:

中添加以下内容
env :BUNDLE_GEMFILE, ENV["/#{path}/Gemfile"]

env :BUNDLE_GEMFILE, ENV["/home/deployer/apps/production_app/current/Gemfile"]

让我知道对你的情况有什么帮助。