简体   繁体   English

Rails cron 每当 gem 错误时,bundle: command not found

[英]Rails cron Whenever gem error, bundle: command not found

I've read this post Whenever errors and tried to implement the recommendations to no avail.我读过这篇文章每当错误并试图实施建议无济于事。 I'm still receiving '/bin/bash: bundle: command not found' error.我仍然收到“/bin/bash: bundle: command not found”错误。 On Amazon EC2.在亚马逊 EC2 上。

which ruby哪个红宝石

/usr/local/bin/ruby

which bundler哪个打包机

/usr/local/bin/bundler

schedule.rb日程表

env :PATH, ENV['PATH']
require File.expand_path('../application', __FILE__)
set :output, "log/cron_log.log"

every 1.minutes do
  rake "calculate:calculate"
end

crontab -e crontab -e

          • /bin/bash -l -c 'cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1' /bin/bash -l -c 'cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1'

tail -f log/cron_log.log tail -f 日志/cron_log.log

/bin/bash: bundle: command not found

When I copy the command out of crontab and run it directly, everything works fine (cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1).当我从 crontab 复制命令并直接运行它时,一切正常(cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2> &1)。 It's the prepending of /bin/bash that's messing this up.正是 /bin/bash 的前置把这搞砸了。

How do I get schedule.rb / whenever gem to recognize correct PATH.我如何获得 schedule.rb/every gem 以识别正确的 PATH。

Forget about PATH settings in cron files.忘记 cron 文件中的 PATH 设置。 Setting the PATH does not work.设置 PATH 不起作用。

Set the path to bundle explicitly in your config/schedule.rb在 config/schedule.rb 中明确设置要捆绑的路径

set :bundle_command, "/usr/local/bin/bundle exec"

Edit: exec added so that task can run编辑:添加 exec 以便任务可以运行

If none of the above solution works this did it for me without any additional setup如果上述解决方案都不起作用,这对我来说没有任何额外的设置

rvm cron setup

This will include all the right paths for gems so you do this on your machine and you are good to go.这将包括宝石的所有正确路径,因此您可以在机器上执行此操作,并且一切顺利。

如果使用rbenv,路径是“/home/YOUR_USER/.rbenv/shims/bundle”,所以你应该写在schedule.rb..的顶部:

set :bundle_command, "/home/YOUR_USER/.rbenv/shims/bundle exec"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM