I had this same problem working through setting up a new CiviCRM instance. There was indeed a lot of set up, but I wanted to share some of it.
TIL Cron isn't enabled by default
Cron does not execute in the same context as the shell testing job.execute. For me, I was running
cv api --user=admin job.execute and it was working fine. However, adding that to crontab did not execute the task. To get cron running, I had to do the following:
sudo service cron status told me cron wasn't even executing!
sudo service cron start solved that
- To view the cron logs, I uncommented the cron line
sudo vi /etc/rsyslog.d/50-default.conf
- To view cron executions
tail -f /var/log/cron.log
The job executes, but what is the result?
Now I knew the command was running, but what was it doing? I modified the cron job to show me
* * * * * /usr/local/bin/cv api --user=admin job.execute > /tmp/cv.cron.log 2>&1
Now I can see the failures, which was cv not finding civicrm.settings.php file. This is where the context of cron differs from my shell. I run
env in my shell and compare it to cron's. By creating a new cron job:
* * * * * env > /tmp/cron.env.log
less /tmp/cron.env.log after
tail -f /var/log/cron.log to make sure it ran. There's no environment! My path is
/usr/bin:/bin. No wonder cv cannot find my site.
Change the current working directory & Use absolute paths
I changed my cron job to change directory into the
/drupal/sites/default folder and now my cron jobs show up. My full crontab command:
* * * * * cd /home/andy/git/drupal/sites/default && /usr/local/bin/cv api --user=cron job.execute > /tmp/cv.cron.log 2>&1
I'm sure your paths will differ. Now that I can see the json response I can remove the
> /tmp/cv.cron.log 2>&1
cron needs to know where your files are.