CRON ' Last job execution ran 2 days ago. Something seems wrong. . '

Nextcloud version (eg, 13.0.0):
Operating system and version (Freenas 11.1):
Apache or nginx version (Apache 2.4):
PHP version (7.1):

Until recently Background jobs completely normally. 2 days ago something happened to cause the message you can see in the topic.

I am not sure what I might have done to cause the issue. Otherwise Nextcloud is running normally apart from the NEWS app stopped pulling new news at the same time.

The two cron jobs I have setup myself:
*/15 * * * * /usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php

  • 1 * * 1 ./usr/local/bin/certbot renew --quiet

Running crontab -l shows me:

  • 1 * * 1 ./usr/local/bin/certbot renew --quiet

Cron is running on my server and I have successfully restarted cron without any change.

This is my first time reaching out for help… I hope someone can point me in the right direction.
thanks.

The output of Nextcloud log in Admin > Logging:

Just the usual Trusted domain error...

The output of your config.php file in /path/to/nextcloud:

$CONFIG = array (
  'instanceid' => 'ocpb0zgomk2a',
  'passwordsalt' => 'jbbbbbbbbbbbbbbbbbbbbbbbbb',
  'secret' => 'bbbbbbbbbbbbbbbbbbbbbbb',
  'auth.bruteforce.protection.enabled' => true,
  'trusted_domains' => 
  array (
    0 => '192.168.0.101',
    1 => 'domain.com',
    2 => 'domain.net',
  ),
  'datadirectory' => '/usr/local/www/apache24/data/nextcloud/data',
  'overwrite.cli.url' => 'http://192.168.0.101/nextcloud',
  'dbtype' => 'mysql',
  'version' => '13.0.0.14',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'name',
  'dbpassword' => 'bbbbbbbbb',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/tmp/redis.sock',
    'port' => 0,
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => 'name',
  'mail_domain' => 'domain.com',
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '465',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'updater.release.channel' => 'stable',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'name@domain.com',
  'mail_smtppassword' => 'bbbbbbbbbbbb',
);

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

Feb 26 03:30:00 nextcloud /usr/sbin/cron[99934]: (www) CMD (/usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php)
Feb 26 03:31:00 nextcloud /usr/sbin/cron[265]: (root) CMD (adjkerntz -a)
Feb 26 03:35:00 nextcloud /usr/sbin/cron[918]: (root) CMD (/usr/libexec/atrun)
Feb 26 03:40:00 nextcloud /usr/sbin/cron[1466]: (root) CMD (/usr/libexec/atrun)
Feb 26 03:45:00 nextcloud /usr/sbin/cron[2176]: (root) CMD (/usr/libexec/atrun)
Feb 26 03:45:00 nextcloud /usr/sbin/cron[2183]: (www) CMD (/usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php)
Feb 26 03:50:00 nextcloud /usr/sbin/cron[2863]: (root) CMD (/usr/libexec/atrun)
Feb 26 03:55:00 nextcloud /usr/sbin/cron[3426]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:00:00 nextcloud /usr/sbin/cron[4157]: (root) CMD (newsyslog)
Feb 26 04:00:00 nextcloud /usr/sbin/cron[4160]: (www) CMD (/usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php)
Feb 26 04:00:00 nextcloud /usr/sbin/cron[4161]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:01:00 nextcloud /usr/sbin/cron[4433]: (root) CMD (adjkerntz -a)
Feb 26 04:05:00 nextcloud /usr/sbin/cron[4877]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:10:00 nextcloud /usr/sbin/cron[5497]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:15:00 nextcloud /usr/sbin/cron[6190]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:15:00 nextcloud /usr/sbin/cron[6192]: (www) CMD (/usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php)
Feb 26 04:20:00 nextcloud /usr/sbin/cron[6747]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:25:00 nextcloud /usr/sbin/cron[7466]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:30:00 nextcloud /usr/sbin/cron[8078]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:30:00 nextcloud /usr/sbin/cron[8084]: (www) CMD (/usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php)
Feb 26 04:31:00 nextcloud /usr/sbin/cron[8165]: (root) CMD (adjkerntz -a)
Feb 26 04:35:00 nextcloud /usr/sbin/cron[8801]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:40:00 nextcloud /usr/sbin/cron[9352]: (root) CMD (/usr/libexec/atrun)
Feb 26 04:45:00 nextcloud /usr/sbin/cron[10058]: (root) CMD (/usr/libexec/atrun)

It repeats as above.... 

Contents /usr/local/www/apache24/data/nextcloud/cron.php

<?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author Artem Sidorenko <artem@posteo.de>
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @author Christopher Schäpers <kondou@ts.unde.re>
 * @author Damjan Georgievski <gdamjan@gmail.com>
 * @author Jakob Sack <mail@jakobsack.de>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Jörn Friedrich Dreyer <jfd@butonic.de>
 * @author Ko- <k.stoffelen@cs.ru.nl>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Oliver Kohl D.Sc. <oliver@kohl.bz>
 * @author Robin Appelman <robin@icewind.nl>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 * @author Steffen Lindner <mail@steffen-lindner.de>
 * @author Thomas Müller <thomas.mueller@tmit.eu>
 * @author Vincent Petry <pvince81@owncloud.com>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

require_once __DIR__ . '/lib/versioncheck.php';

try {

	require_once __DIR__ . '/lib/base.php';

	if (\OCP\Util::needUpgrade()) {
		\OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG);
		exit;
	}
	if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
		\OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG);
		exit;
	}

	// load all apps to get all api routes properly setup
	OC_App::loadApps();

	\OC::$server->getSession()->close();

	// initialize a dummy memory session
	$session = new \OC\Session\Memory('');
	$cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
	$session = $cryptoWrapper->wrapSession($session);
	\OC::$server->setSession($session);

	$logger = \OC::$server->getLogger();
	$config = \OC::$server->getConfig();

	// Don't do anything if ownCloud has not been installed
	if (!$config->getSystemValue('installed', false)) {
		exit(0);
	}

	\OC::$server->getTempManager()->cleanOld();

	// Exit if background jobs are disabled!
	$appMode = \OCP\BackgroundJob::getExecutionType();
	if ($appMode == 'none') {
		if (OC::$CLI) {
			echo 'Background Jobs are disabled!' . PHP_EOL;
		} else {
			OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!')));
		}
		exit(1);
	}

	if (OC::$CLI) {
		// set to run indefinitely if needed
		if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
			@set_time_limit(0);
		}

		// the cron job must be executed with the right user
		if (!function_exists('posix_getuid')) {
			echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
			exit(1);
		}
		$user = posix_getpwuid(posix_getuid());
		$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
		if ($user['name'] !== $configUser['name']) {
			echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL;
			echo "Current user: " . $user['name'] . PHP_EOL;
			echo "Web server user: " . $configUser['name'] . PHP_EOL;
			exit(1);
		}

		// We call ownCloud from the CLI (aka cron)
		if ($appMode != 'cron') {
			\OCP\BackgroundJob::setExecutionType('cron');
		}

		// Work
		$jobList = \OC::$server->getJobList();

		// We only ask for jobs for 14 minutes, because after 15 minutes the next
		// system cron task should spawn.
		$endTime = time() + 14 * 60;

		$executedJobs = [];
		while ($job = $jobList->getNext()) {
			if (isset($executedJobs[$job->getId()])) {
				$jobList->unlockJob($job);
				break;
			}

			$job->execute($jobList, $logger);
			// clean up after unclean jobs
			\OC_Util::tearDownFS();

			$jobList->setLastJob($job);
			$executedJobs[$job->getId()] = true;
			unset($job);

			if (time() > $endTime) {
				break;
			}
		}

	} else {
		// We call cron.php from some website
		if ($appMode == 'cron') {
			// Cron is cron :-P
			OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
		} else {
			// Work and success :-)
			$jobList = \OC::$server->getJobList();
			$job = $jobList->getNext();
			if ($job != null) {
				$job->execute($jobList, $logger);
				$jobList->setLastJob($job);
			}
			OC_JSON::success();
		}
	}

	// Log the successful cron execution
	\OC::$server->getConfig()->setAppValue('core', 'lastcron', time());
	exit();

} catch (Exception $ex) {
	\OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL);
} catch (Error $ex) {
	\OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL);
}

You should let the www-data user run the cronjob, not root.

Aside from that:
What happens if you execute sudo -u www-data /usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php directly?

sf-janz,
thanks for responding.
the cron jobs I created are created with user www. I think the other cron jobs were system created… I am not sure. It all did work until recently as I mentioned.

I executed manually as you suggested and got back the following:

There is problem, but I am not sure how to interpret it?
thanks

Thinking back to what I might have done to create the problem (I never doubted it was something I had done…) It might be related to my installing imagick as per:

I do not know how to fix the problem - suggestions welcome…

Here is a list of required and recommended php modules (some apps might require additional packages):
https://docs.nextcloud.com/server/13/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation

On FreeBSD, you normally have the package manager pkg to install additional software, not sure if it is different on FreeNAS.

Looking in var/log/messages I found:
Feb 24 12:14:07 nextcloud pkg: php71-7.1.12_1 deinstalled
Feb 24 12:14:09 nextcloud pkg: php56-5.6.33 installed

I reinstalled php71 and cron has started again…