V
V
Vitali2014-05-13 17:07:45
Ruby on Rails
Vitali, 2014-05-13 17:07:45

Why doesn't Bundle exec rake work in Cron?

There is a server on Ubuntu 13.10.
There is a project on Ruby On Rails and several rake tasks that work on cron every 3 minutes.
There is a gem Whenever which syntax is like

every 3.minutes do
  rake 'update_balance'
end
Converts to string 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'
So, this script, being run manually (with the same line as in Cron), works great and makes certain entries in the database.
When placed in Cron, the script leaves the following entries in the /var/log/syslog file
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')
BUT, at the same time, the script definitely does not work out, i.e. I don't see any results from running it, and when I try to append &>/tmp/mycommand.log to the Cron task , the file is simply cleared each time the next cron task is run, although when run manually, the output will be something like this:
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
I would be grateful for any tips on where to dig and what to look for?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitali, 2014-05-14
@Screatch

This question on Stackoverflow helped me solve my problem:
stackoverflow.com/questions/2388087/how-to-get-cro...

P
pomeo, 2014-05-13
@pomeo

how is ruby ​​installed, rvm?

I
IgorVol, 2016-12-28
@IgorVol

The cron is run as a cron user
. His PATH environment most likely does not contain rvm, ruby, bundle, or the like. So the script doesn't work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question