运行 whenever -w
后,我的 cron 作业在本地计算机上运行良好,在部署到我的 VPS 后,我收到此错误,版本 20150415044915 不存在
。有什么想法吗?
我查看了 crontab -e,路径看起来也很好,其中 20150502114703 是正确的版本:
0 1 * * 1 /bin/bash -l -c 'cd /home/hey_production/releases/20150502114703 && bin/rails runner ....
错误日志:
/usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler/definition.rb:22:in `build': /home/hey_production/releases/20150415044915/Gemfile not found (Bundler::GemfileNotFound)
from /usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler.rb:154:in `definition'
from /usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler.rb:117:in `setup'
from /usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler/setup.rb:17:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from bin/rails:14:in `<main>'
最佳答案
基本上缺少告诉 cron 去哪里寻找 Gemfile 的环境变量。因此,当 cron 尝试运行它时,您需要在环境中添加该变量。
您可以在 schedule.rb
中执行此操作:
env BUNDLE_GEMFILE, ENV["/home/hey_production/current/Gemfile"]
或者直接在 crontab 文件中使用命令 crontab -e
(在 cron 条目之前):
BUNDLE_GEMFILE="/home/hey_production/current/Gemfile"
希望有帮助。
编辑
忘记了 schedule.rb
schedule.rb 中的行应该是这样的。
env :BUNDLE_GEMFILE, ENV["/#{path}/Gemfile"]
或
env :BUNDLE_GEMFILE, ENV["/home/hey_production/current/Gemfile"]
关于ruby-on-rails - 使用 Capistrano 3 运行 Cron 作业时以及 gem 时未找到 Gemfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002151/