Cron not running on nc25.0.1

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 25.0.1
Operating system and version (eg, Ubuntu 20.04): Debian 10
Apache or nginx version (eg, Apache 2.4.25): 2.4.38
PHP version (eg, 7.4): 8.1.12 is what php -v gives

The issue you are facing:

I get a warning for background jobs not running, despite having */5 * * * * php -f /var/www/nextcloud/cron.php --define apc.enable_cli=1 when I run crontab -u www-data -l as root. Also same if I don’t have --define apc.enable_cli=1.

I can’t seem to run anything as the www-data user; if I try su www-data it says account not available, so I can’t try running the cronjob manually.

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

Steps to replicate it:

  1. Start the server

The output of your Nextcloud log in Admin > Logging:

No relevant errors

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

$CONFIG = array (
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '',
  ),
  'datadirectory' => '/var/www/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '25.0.1.1',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'instanceid' => '',
  'skeletondirectory' => '',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'updater.secret' => '',
  'updater.release.channel' => 'beta',
);

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

[Wed Nov 09 00:00:03.842700 2022] [ssl:warn] [pid 303] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Wed Nov 09 00:00:03.843010 2022] [ssl:warn] [pid 303] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Wed Nov 09 00:00:03.843178 2022] [mpm_prefork:notice] [pid 303] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Wed Nov 09 00:00:03.843186 2022] [core:notice] [pid 303] AH00094: Command line: '/usr/sbin/apache2'
[Wed Nov 09 03:08:11.529743 2022] [mpm_prefork:notice] [pid 303] AH00169: caught SIGTERM, shutting down
[Wed Nov 09 03:08:20.648750 2022] [ssl:warn] [pid 289] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Wed Nov 09 03:08:20.649166 2022] [ssl:warn] [pid 289] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
PHP Warning:  PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/lib/php/20180731/imagick.so (/usr/lib/php/20180731/imagick.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/imagick.so.so (/usr/lib/php/20180731/imagick.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[Wed Nov 09 03:08:20.692824 2022] [ssl:warn] [pid 307] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Wed Nov 09 03:08:20.693183 2022] [ssl:warn] [pid 307] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Wed Nov 09 03:08:20.698797 2022] [mpm_prefork:notice] [pid 307] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Wed Nov 09 03:08:20.698838 2022] [core:notice] [pid 307] AH00094: Command line: '/usr/sbin/apache2'
[Wed Nov 09 03:08:21.520753 2022] [proxy_fcgi:error] [pid 313] [client 192.168.1.241:59352] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Doctrine\\DBAL\\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php:139\nStack trace:\n#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\\DB\\Connection->connect()\n#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\\DBAL\\Connection->getWrappedConnection()\n#2 /var/www/nextcloud/lib/private/DB/Connection.php(261): Doctrine\\DBAL\\Connection->executeQuery()\n#3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\\DB\\Connection->executeQuery()\n#4 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 /var/www/nextcloud/lib/private/AppConfig.php(411): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n#6 /var/www/nextcloud/lib/private/AppConfig.php(176): OC\\AppConfig->loadConfigValues()\n#7 /var/www/nextcloud/lib/p...'

Typically the path variable isn’t in effect in cron jobs, so you may need to specify the full path to php as well.

Can you confirm this is the correct user name that runs your Apache service? You should be able to run a shell as that user. Maybe try sudo -u www-data

Typically the path variable isn’t in effect in cron jobs, so you may need to specify the full path to php as well.

I tried */5 * * * * /usr/bin/php -f /var/www/nextcloud/cron.php --define apc.enable_cli=1 but with no luck.

Can you confirm this is the correct user name that runs your Apache service? You should be able to run a shell as that user. Maybe try sudo -u www-data

Sorry, I have no idea how to do that. Since I’m logged in as root (the only user I know how to login as) I can’t do sudo, it says command not found.

edit: when the nextcloud error logs finally loaded, I did see this entry from 10 days ago:

[cron] Error: Doctrine\DBAL\Exception\ConnectionLost: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away at <<closure>>

0. /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1780
   Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert(Doctrine\DBAL\Driver\PDO\Exception {}, Doctrine\DBAL\Query {})
1. /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1719
   Doctrine\DBAL\Connection->handleDriverException(Doctrine\DBAL\Driver\PDO\Exception {}, Doctrine\DBAL\Query {})
2. /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1173
   Doctrine\DBAL\Connection->convertExceptionDuringQuery(Doctrine\DBAL\Driver\PDO\Exception {}, "UPDATE `oc_appc ... )", [4,"backgroundjob","lastjob",4], [2,2,2,2])
3. /var/www/nextcloud/lib/private/DB/Connection.php line 270
   Doctrine\DBAL\Connection->executeStatement("UPDATE `oc_appc ... )", [4,"backgroundjob","lastjob",4], [2,2,2,2])
4. /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php line 354
   OC\DB\Connection->executeStatement("UPDATE `oc_appc ... )", {dcValue1: 4,dcV ... 4}, {dcValue1: 2,dcV ... 2})
5. /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 287
   Doctrine\DBAL\Query\QueryBuilder->execute()
6. /var/www/nextcloud/lib/private/AppConfig.php line 252
   OC\DB\QueryBuilder\QueryBuilder->execute()
7. /var/www/nextcloud/lib/private/AllConfig.php line 209
   OC\AppConfig->setValue("backgroundjob", "lastjob", 4)
8. /var/www/nextcloud/lib/private/BackgroundJob/JobList.php line 315
   OC\AllConfig->setAppValue("backgroundjob", "lastjob", 4)
9. /var/www/nextcloud/cron.php line 154
   OC\BackgroundJob\JobList->setLastJob(OCA\Federation\SyncJob {})

at 2022-10-30T17:24:32+00:00

I thought at that point it was running background jobs just fine (I hadn’t had any warnings 10 days ago, my cron issues only started yesterday with 25.0.1), but it is a cron-related error, so maybe it helps.

Prepend the paths for the enviroment to the crontab for www-data like this:

crontab -e -u www-data

Add at the beginning:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

and as for NC’s cronjobs:

*/5 * * * * php -f /var/www/nextcloud/cron.php

Save the new crontab.

If the above doesn’t work there seems to be something wrong with your server config (looking at the logs you have posted it does not looking all too good (i.e. database connection errors etc.)).

Sorry, no luck with that… I might just nuke my LXC and do a new one, start from scratch. No idea how all these db errors showed up and all my data is on shared folders anyway so no loss there.

If this happens again you could try to increase the values for wait_timeout and max_allowed_packet in the MySQL config: /etc/mysql/my.cnf

Also take a look at the documentation, where you can find configuration examples for MySQL/MariaDB: https://docs.nextcloud.com/server/latest/admin_manual/configuration_database/linux_database_configuration.html