0

Struggling with cron jobs. Ubuntu 11.10 on the server.

Until recently had whenever cron jobs running successfully several times a day; then due to another problem I had to remove RVM from the server and go back to ruby 1.9.3 installed without RVM (I'm sure this is something to do with it)

There is no .rvmrc file in my app

Now, the cron jobs are somehow failing as I can see from syslog:

Jun 30 08:03:01 ip-10-251-30-96 CRON[18706]: (ubuntu) CMD (/bin/bash -l -c 'cd /var/www/my_app/app/releases/201300629090954 && script/rails runner -e production '\''User.remind_non_confirmed_users'\''')
Jun 30 08:03:01 ip-10-251-30-96 CRON[18705]: (CRON) error (grandchild #18706 failed with exit status 127)
Jun 30 08:03:01 ip-10-251-30-96 CRON[18705]: (CRON) info (No MTA installed, discarding output)

If I run that command manually (with env - /bin/bash -l -c '...' ) it runs fine..

I'm going to add "set :output, 'tmp/whenever.log'" to whenever to see what is going on, but I suspect it is an issue with the ruby version / path or something.

Any idea how I could diagnose / fix this properly??

this is my cron/whenever job:

3 8 * * * /bin/bash -l -c 'cd /var/www/my_app/app/releases/20130629090954 && script/rails runner -e production '\''User.remind_non_confirmed_users'\''' 

many thanks

bobomoreno
  • 2,848
  • 5
  • 23
  • 42

2 Answers2

0

To help diagnose what's going on, I usually capture the cron output into a separate log file. There's probably an error that's just not being recorded anywhere.

@hourly bash -lc 'cd /path/to/app; RAILS_ENV=production bundle exec rake remind_non_confirmed_users' >> /path/to/app/log/tasks.log

Also, I prefer creating rake tasks for cron jobs as opposed to runners. A little easier to invoke via the command line than runners, for me at least.

Kyle Truscott
  • 1,537
  • 1
  • 12
  • 18
  • strangly the log files do not get created; yet the 'ubuntu' user has write permissions to where I'm trying to write them.. (/tmp) – bobomoreno Jun 30 '13 at 15:08
  • Well, you're just trying to figure out why the task it's failing, right? Maybe slap your output log somewhere easy like $HOME for now so you can get at the ruby issue. – Kyle Truscott Jun 30 '13 at 15:22
0

I'm still not sure what was going on, running Whatever with 'set :output' should have created log files, but it didn't, yet the jobs are still failing (and write permissions were there for the log files).

I got so fed up I redeveloped the solution without using script/runner, in stead have cron just call a URL that then takes care of matters as a delayed job. For our particular situation this has a number of additional benefits, though I know it is not ideal for many.

thanks for the suggestions

bobomoreno
  • 2,848
  • 5
  • 23
  • 42