【问题标题】:How to make crontab use the correct rake and refer to gems in vendor/bundle如何使 crontab 使用正确的 rake 并参考 vendor/bundle 中的 gem
【发布时间】:2012-12-22 04:49:19
【问题描述】:

我希望调用 rake 任务的 cron 作业使用安装在 [rails_app]/vendor/bundle 或 [rails_app]/vendor/cache 中的 gem。目前,我的系统 gem 已经过时了,但由于我无法控制的各种原因,我无法更新它们。

我尝试使用bundle exec,但这似乎不起作用。我得到的错误是 usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/spec_set.rb:88:in 'materialize': 找不到 rake-0.9.2.2来源 (Bundler::GemNotFound)

我相信这是因为我的系统的 rake 已过时。我尝试在cron作业中使用bundle exec rake _0.9.2.2_ [my_task],但出现了同样的错误

我尝试了whenever gem;这产生了确切的错误。

所以我想我有两个问题:

  1. 如何让 cron 使用正确的 rake 版本?并且
  2. 如何将其指向已在供应商/捆绑包或供应商/缓存中的 gem?

请注意,该站点在部署在 Phusion Passenger 中时可以正常工作。

【问题讨论】:

  • 是的,我这样做了,但没有成功。我的命令是cd /home/[rails_app] && RAILS_ENV=production bundle exec rake _0.9.2.2_ [my_task]

标签: ruby-on-rails cron rake bundler


【解决方案1】:

在为同一问题寻找解决方案时,我发现 this Thread 有几个提示。

对我来说,快速简单的方法就是将 cron 命令作为登录 shell 运行 - 像这样:

* * * * * /bin/bash -l -c 'bundle exec rake _0.9.2.2_ [my_task]' 2>&1

结尾 2>&1 只是为了确保在 cron 日志中收到错误。另请参阅man bash 了解更多信息!

【讨论】:

  • 我最终使用 RVM 和您的 bin/bash -l -c 作为解决方案作为解决方法。我将在另一个项目中尝试不使用 RVM 的解决方案,但我会将其标记为已接受。谢谢。
猜你喜欢
  • 2015-10-21
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2012-01-06
  • 1970-01-01
  • 1970-01-01
  • 2020-01-16
相关资源
最近更新 更多