Nextcloud thinks cron job hasn't run in 3 days; it actually runs every 5 minutes

Nextcloud version 17.0.2
Operating system and version Debian Buster
Apache or nginx version Apache 2.4.38-3+deb10u3
PHP version 7.3

The issue you are facing:

The Overview page on the web UI reports:

Last background job execution ran 3 days ago. Something seems wrong. Check the background job settings.

This message started after I switched from webcron to system cron, as directed by the News app.

I have followed the instructions for setting up a cron job, and checking /var/log/syslog I can see that the cron job is in fact running every 5 minutes.

crontab -u www-data -l
...
*/5  *  *  *  * php -f /var/www/nextcloud/cron.php
root@XXXXX:/var/log# grep CRON /var/log/syslog | tail
Dec 27 09:45:02 cabbagetown CRON[25316]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 27 09:50:01 cabbagetown CRON[25330]: (www-data) CMD (php -f /var/www/nextcloud/cron.php)
Dec 27 09:55:01 cabbagetown CRON[25350]: (www-data) CMD (php -f /var/www/nextcloud/cron.php)
Dec 27 09:55:01 cabbagetown CRON[25351]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 27 10:00:01 cabbagetown CRON[25407]: (www-data) CMD (php -f /var/www/nextcloud/cron.php)
Dec 27 10:05:01 cabbagetown CRON[25423]: (www-data) CMD (php -f /var/www/nextcloud/cron.php)
Dec 27 10:05:01 cabbagetown CRON[25424]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 27 10:09:01 cabbagetown CRON[25437]: (root) CMD (  [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean)
Dec 27 10:09:01 cabbagetown CRON[25438]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Dec 27 10:10:02 cabbagetown CRON[25499]: (www-data) CMD (php -f /var/www/nextcloud/cron.php)

I don’t know what the root cron job is, it’s not something I set manually. I assume it was set up by the Debian package manager.

Is this the first time you’ve seen this error? (Y):

Steps to replicate it:

  1. login to the web interface with an admin user
  2. check the overview tab in the setting menu

The output of your Nextcloud log in Admin > Logging:

Many info lines from the updater, related to updating from 17.0.1 to 17.0.2, which I did hoping it might fix the problem (it didn’t). Prior to that some errors regarding the php-pgsql module, which I fixed before getting the current problem. (that error hasn’t recurred since).

eg:

[updater] Info: \OC\Updater::resetLogLevel: Reset log level to Warning(2)

GET /nextcloud/core/ajax/update.php?requesttoken=pQXphw9ceMumJNOcpsTBWK2YecXqY7ZaDFX81vJ9ppc%3D%3A627C4jgPTPL8b6fxwbzyOuWrM6SFFoFoNGaasrEW59g%3D
from 70.54.111.45 at 2019-12-24T03:34:59+00:00

The output (I think you mean contents?) of your config.php file in
/path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'passwordsalt' => <deleted>,
  'secret' =>  <deleted>,
  'trusted_domains' => 
  array (
    0 =>  <deleted>,,
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '17.0.2.1',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'instanceid' =>  <deleted>,
  'dbuser' => 'oc_admin',
  'dbpassword' =>  <deleted>,
  'mysql.utf8mb4' => true,
  'installed' => true,
  'maintenance' => false,
  'updater.secret' =>  <deleted>,
  'theme' => '',
  'loglevel' => 2,
  'mail_from_address' =>  <deleted>,
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' =>  <deleted>,
  'mail_smtphost' =>  <deleted>,
  'mail_smtpport' => '465',
  'mail_smtpauthtype' => 'PLAIN',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpauth' => 1,
  'mail_smtpname' =>  <deleted>,
  'mail_smtppassword' =>  <deleted>,
);

The output of your Apache/nginx/system log in /var/log/____:

root@XXXXX:/var/log/apache2# cat error.log
[Fri Dec 27 00:00:02.124691 2019] [mpm_prefork:notice] [pid 606] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1d configured -- resuming normal operations
[Fri Dec 27 00:00:02.124749 2019] [core:notice] [pid 606] AH00094: Command line: '/usr/sbin/apache2'
[Fri Dec 27 06:20:23.753092 2019] [php7:error] [pid 22236] [client 45.251.240.44:58077] script '/var/www/html/router.php' not found or unable to stat
[Fri Dec 27 06:26:09.119708 2019] [php7:error] [pid 22256] [client 75.147.197.137:59826] script '/var/www/html/download.php' not found or unable to stat, referer: http://plantarum.ca/download.php?file=../../../../../../../../../../../../etc/passwd
[Fri Dec 27 07:51:58.030937 2019] [php7:error] [pid 22239] [client 45.251.240.44:51777] script '/var/www/html/router.php' not found or unable to stat
[Fri Dec 27 10:11:30.667923 2019] [authz_core:error] [pid 25507] [client 23.233.87.120:33124] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata

I have additional issues in my Overview page. I have been working down the list, and haven’t tried to fix these yet:

  • Your web server is not properly set up to resolve “/.well-known/caldav”.
    Further information can be found in the documentation.

  • Your web server is not properly set up to resolve “/.well-known/carddav”.
    Further information can be found in the documentation.

  • No memory cache has been configured. To enhance performance, please
    configure a memcache, if available. Further information can be found in
    the documentation.

  • Some columns in the database are missing a conversion to big int. Due to
    the fact that changing column types on big tables could take some time
    they were not changed automatically. By running ‘occ
    db:convert-filecache-bigint’ those pending changes could be applied
    manually. This operation needs to be made while the instance is offline.
    For further details read the documentation page about this.

    • mounts.storage_id
    • mounts.root_id
    • mounts.mount_id

Is my cron job running properly? What do I need to do to fix the cron job, or set up nextcloud so that it recognizes the cron job is running as expected?

Have you tried to run the cron command manually? Anything in your logs?

I have run the cron job manually from the command line, and it appears to work without error. I didn’t find anything in the logs indicating an error, but there are a lot of different logs - which one should I be checking?

nextcloud.log for example

Where should that be? It’s not in /var/log/, or /var/www/nextcloud? Maybe I need to set that up?

possibly related, I’ve just discovered I can’t run php occ at all. It always produces a memory exhausted error:

sudo -u www-data php occ 
PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 32768 bytes) in /var/www/nextcloud/3rdparty/composer/autoload_static.php on line 411

I’ve found /var/www/nextcloud/data/nextcloud.log, and there’s nothing new in it - the last entries are related to the update I did three days ago.

However, when I tried to run cron.php just now at the command line, I got the memory exhausted error:

sudo -u www-data php cron.php
PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 32768 bytes) in /var/www/nextcloud/3rdparty/composer/autoload_static.php on line 411

When I last did this three days ago, the command appeared to run, and returned without error.

I think I have solved the problem - the memory limit for php wasn’t properly set. I had previously got the warning about the php memory limit being too low. So I set that config in the php/7.3/apache2/php.ini file. That appeared to work, as the warning went away.

But the cron job is run by the system, not by apache2, and the system uses the configuration in php/73/cli/php.ini I think? I’ve updated the memory limit in that file now too, and no longer get the warning about the cron job not having run in three days.

My problem is even weirder (Nextcloud 20.0.8 on a plesk driven web hosting. ): On the settings page I receive an error that some background jobs haven’t been done since two months.

Using Webchron I can call the url and I receive success → no change on settings page.

Using Cron, I can run php cron.php from the command line → no change on settings page.

I everything running fine and just the settings page stuck?
Cheers

This solution did not work for me. drewjosh, did you solve your problem? It seams that I have the same behaviour as yours.

In my case, everything was working correctly and I have never seen this error on my server. It came after I updated to 21.0.3 from the previous version.

Then it’s a different problem and you should open a new thread, this is already solved.

I could solve the problem by inserting this in php.ini:

apc.enable_cli=1