简体   繁体   English

Bundle exec rake不在cron中运行

[英]bundle exec rake doesn't run in cron

I did some researching but all cron and bundle exec related didn't cover the problem I am having so excuse me again if this had been discussed. 我做了一些研究,但是所有与cron和bundle exec相关的问题都没有解决,如果已经讨论过,我将再次为我辩解。

I am running Ubuntu 13.10 and have a Ruby On Rails app that have few rake tasks that needs to be run on Cron every few minutes or so. 我正在运行Ubuntu 13.10,并且有一个Ruby On Rails应用程序,该应用程序几乎不需要每隔几分钟就在Cron上运行的一些rake任务。

I run a whenever gem, with the help of which, this syntax 我在任何时候运行宝石,借助该语法

every 3.minutes do
  rake 'update_balance'
end

transforms to this line in crontab file 转换为crontab文件中的这一行

0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent'

And when I copy this line exactly 当我完全复制此行时

/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent'

and run in it console, it runs perfectly fine and updates several records in database, as supposed. 并在它的控制台中运行,它运行得很好,并且可以按预期更新数据库中的多个记录。

But when set to cron, I can see it running in /var/log/syslog file, but nothing is really executed. 但是当设置为cron时,我可以看到它在/ var / log / syslog文件中运行,但是实际上并没有执行任何操作。

May 13 13:06:01 sandbox2 CRON[9656]: (root) CMD (/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent')
May 13 13:06:01 sandbox2 CRON[9655]: (CRON) info (No MTA installed, discarding output)
May 13 13:09:01 sandbox2 CRON[9789]: (root) CMD (/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent')

Even when I add &>/tmp/mycommand.log to crontab command, every next launch of cron command just completely truncates this file, however again, If I launch it manually, it works nicely and leaves me with this output. 即使我将&> / tmp / mycommand.log添加到crontab命令中,每次下一次启动cron命令都会完全截断该文件,但是,再次,如果我手动启动它,它会很好地工作,并留下此输出。

2014-05-13T11:11:25Z 10292 TID-2asbo INFO: Sidekiq client with redis options  {:url=>"redis://127.0.0.1"}
Sent task for updating 2 users

Any help with this issue is much appreciated. 非常感谢对此问题的任何帮助。 Thanks. 谢谢。

I've encountered problems like this before due to the fact that cron runs as a different user. 由于cron以不同的用户身份运行,因此我之前遇到过类似的问题。 With rake in particular, i have to use the full path to rake since the cron user doesn't have the right folder in it's PATH. 特别是对于rake,我必须使用完整路径进行rake因为cron用户在PATH中没有正确的文件夹。

So, my cron lines for rake tasks look like this: 因此,我用于耙任务的cron行如下所示:

30 8 * * 1 cd /ebs/www/apps/myproject/www && /usr/local/bin/rake mailer:send_weekly_expiring_users_reminder RAILS_ENV=production

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

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