Domanda

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.

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.

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

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.

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.

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.

È stato utile?

Soluzione

I've encountered problems like this before due to the fact that cron runs as a different user. 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.

So, my cron lines for rake tasks look like this:

30 8 * * 1 cd /ebs/www/apps/myproject/www && /usr/local/bin/rake mailer:send_weekly_expiring_users_reminder RAILS_ENV=production
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top