I’m struggling very much to get Nextcloud to use crontab based background jobs, to the point where I must ask for some help/advice. I’m already beyond my regular knowledge level on Linux/Nextcloud.
When I set my Nextcloud instance to use Cron for background jobs, Nextcloud always tells me that no background job has been performed for the last xx minutes/hours. AJAX appears to work though.
My Nextcloud 25.0.4 installation is pretty brand new (no VM or Snap, but manual installation), as is my Linux Ubuntu Server 22.10 installation.
As part of my NC installation, I did implement a cron job every 5 minutes, by entering …
sudo crontab -u www-data -e
… and editing the cron in VI. I added the recommended …
*/5 * * * * php -f /var/www/nextcloud/cron.php
… code at the bottom of the Cron and saved it. The address to my cron.php file in the code is correct.
This didn’t work, Nextcloud web interface tells me no background jobs are performed when Cron is selected.
So I researched out that the code “PHP” (in the code above) may actually point to a different PHP version than Nextcloud uses (v8.1 in my case), if I – by some chance – have several different PHP versions on my system.
Informed by the discussion in this thread, I ran …
sudo update-alternatives –config php
… and was presented with a menu of 3 different PHP implementations, and could choose which one the system is to regard as the default one. I selected the right one, and the prompt confirmed that PHP v8.1 was now regarded as system default.
Still no improvement in Cron job deficiency.
So I tried reformatting the code in the crontab, trying …
*/5 * * * * php8.1 -f /var/www/nextcloud/cron.php
*/5 * * * * php -f /var/www/nextcloud/cron.php
*/5 * * * * php-cli -f /var/www/nextcloud/cron.php
*/5 * * * * /usr/bin/php -f /var/www/nextcloud/cron.php
*/5 * * * * /usr/bin/php8.1 -f /var/www/nextcloud/cron.php
I restarted the machine every time I changed it (just to be sure the adjustment was fully implemented right away). Still no luck.
Btw I’m using the Nextcloud web interface, administrator settings to check however Cron has done some background job or not. Currently I’m running Ajax, and it appears to work.
I do remember though, that when I first created the crontab, during my installation process, I was told – by the manual I was using at the time – that not only must the user be “www-data”, but this user was supposedly also a part if a ‘Group’ called www-data too (?) So therefore, the manual said, instructed me to create the cron job by entering both user and usergroup. Like so:
Sudo crontab -u www-data:www-data -e
When I adjusted the code between different PHP versions and options (see above) I did not however use the term www-data:www-data, but simply www-data. When I check for existing cronjobs for the user www-data, my cron job is listed there, with the code I entered in. So it is correct so far. But might I have corrupted something by adding the user-group to the command as well?
With this, I’m at an end of what I have researched out so far, but I still feel it should work with this. What I have now are a few suspicions and loose ends, to offer for errorsearching.
Hints of further errors?
For example, whenever I enter into the administrator settings in the Nextcloud web interface, and I have AJAX selected, the web interface always says the last background job was performed “seconds ago”. It never says “was performed 4 minutes ago”, or 1 minute, or 2 minutes. It is ALWAYS “just seconds ago”.
This gives me the impression that the AJAX background job is performed BECAUSE I enter into the administrator settings in the web interface, since it is ALWAYS just seconds ago.
I’m not sure if I’m being paranoid here, but … it doesn’t feel right. Might this be an indication of something wrong that could be part of why also the cron appears funky? I’m just fishing here.
NC Errorlogs
I also looked into the errorlog in the Nextcloud web interface, and I was able to spot some potentially relevant errormessages there. It seems that each time I selected Cron as the background job type, just to see if it by any chance just suddenly pop started working or turned on, it seems Nextcloud wrote many errorlogs during those specific time periods. In particular this one, which there are many of:
[files_antivirus] Error: OCP\Files\NotPermittedException: at <>
0. /var/www/nextcloud/apps/files_antivirus/lib/Item.php line 185
OC\Files\Node\File->fopen()
- /var/www/nextcloud/apps/files_antivirus/lib/Item.php line 75
OCA\Files_Antivirus\Item->getFileHandle()- /var/www/nextcloud/apps/files_antivirus/lib/Scanner/ScannerBase.php line 89
OCA\Files_Antivirus\Item->fread()- /var/www/nextcloud/apps/files_antivirus/lib/BackgroundJob/BackgroundScanner.php line 313
OCA\Files_Antivirus\Scanner\ScannerBase->scan()- /var/www/nextcloud/apps/files_antivirus/lib/BackgroundJob/BackgroundScanner.php line 110
OCA\Files_Antivirus\BackgroundJob\BackgroundScanner->scanOneFile()- /var/www/nextcloud/lib/public/BackgroundJob/Job.php line 78
OCA\Files_Antivirus\BackgroundJob\BackgroundScanner->run()- /var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php line 103
OCP\BackgroundJob\Job->start()- /var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php line 93
OCP\BackgroundJob\TimedJob->start()- /var/www/nextcloud/cron.php line 177
OCP\BackgroundJob\TimedJob->execute()
GET /cron.php
from 185.65.xxx.xxx at 2023-03-05T18:13:55+00:00
I do have ClamAV installed, and I call on it from Nextcloud web interface by “ClamAV Executable” in /usr/bin/clamscan using “ICAP preset: ClamAV”.
Apps interfering?
I also have quite a few Nextcloud Apps already installed, and I am thinking that perhaps one of those could interfere with the Cron job execution? If anyone knows …?
Manually triggering Cron job
I was just asked to try the following Linux command …
sudo -u www-data php8.1 -f /var/www/nextcloud/cron.php
… and the response was a somewhat interesting …
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
I seem to recall having the ACPu included in the installation process of Nextcloud, and I do have this line in config.php …
‘memcache.local’ => ‘\OC\Memcache\APCu’,
… but if someone knows how to re-check/verify that ACPu is operational or not, I’m all up for it.
A longshot: spelling error in code?
I also spotted this thread, which claims a similar problem, and addresses a simple spelling error in a line of code to be the culprit. But I’m not sure where to look for this code line(?) It’s not in my config.php.
Thank so much in advance for any idea or comments, to take this problem further towards a solution.