4

I am attempting to use CV to call job.execute to run my scheduled tasks as described in the CiviCRM Documentation. I am using Drupal 7. I have several independent sites running on the server.

It works fine when I call it manually (for each site):

sudo cv api job.execute --user=admin --cwd=/var/www/html/siteroot

The tasks also work when I call them manually from the UI (for all sites)

Crontab is set up with the following:

*/5 * * * * cv api job.execute --user=admin --cwd=/var/www/html/siteroot

the syslog shows no problems and that the cron fires (example output):

Nov  1 10:15:01 live CRON[8991]: (root) CMD (cv api job.execute --user=admin --cwd=/var/www/html/siteroot)

However,

the scheduled tasks appear to not be running. I have configured several to run "whenever cron is run" but they still do not run unless I fire them manually.

Is there something I am missing? Is there a log in Civi where I can see if the command is being received?

I am using Drupal 7, php7.0, CiviCRM 5.3 on Ubuntu 16.04

2 Answers 2

4

Ok so this may seem like a silly issue to some but after some messing around I figured out cron didn't have access to the path where CV was installed so to fix it the crontab entry had to be changed to:

*/5 * * * * /usr/local/bin/cv api job.execute --user=admin --cwd=/var/www/html/siteroot

There was no error as the mailer deamon was not firing correctly so no error was being sent or logged.

Cron does not generally have access to the path that a shell root user does, which is why running the command cv as root works just fine.

3
  • 2
    debug suggestions here: chat.civicrm.org/civicrm/pl/sq974fi5c783xgu5dyisb6a6gw (probably would have led you to same solution, might be good for next time). also useful if you want to understand why cron environment is different to interactive environment - serverfault.com/questions/698577/… or man 5 crontab Commented Nov 27, 2018 at 20:39
  • 2
    you probably want to NOT run your CiviCRM cron as the root user; it should run as the same system user as you usually run CiviCRM (eg httpd, www-data, or your web application run user). otherwise you'll end up with files owned by root which CiviCRM can't modify when running from web. see docs.civicrm.org/sysadmin/en/latest/setup/jobs/… Commented Nov 27, 2018 at 20:40
  • 1
    I did not understand cron's environment at all - which is why I got confused. That was a very informative link thank you.
    – tanbog
    Commented Nov 28, 2018 at 5:06
1

Is the user "admin" defined in Drupal? If not some commands will not fire under cv. cv needs a user under "username" that is recognized by Drupal as having the rights to fire the command you're interested in. I had this same issue myself which was fixed by identifying an authorized Drupal user.

1
  • 1
    Admin is defined in my case but that would probably be an issue for a lot of other people.
    – tanbog
    Commented Nov 28, 2018 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.