Crontab Issue. Last job execution ran 4 hours ago. Something seems wrong

The crontab issue has been around for over a week. Each day I start up Nextcloud, I see the same cron message. I have read numerous articles and tried a number of different things to fix it. So far nothing has worked. Any help with this issue would be greatly appreciated. I have just recently setup my Unraid server and installed the NextCloud docker container. So far things are going very well except for this persistent cron issue.

Nextcloud version: Nextcloud Hub 3 (25.0.2)
Operating system and version: Linux 5.19.17-Unraid x86_64
Apache or nginx version: nginx/1.20.2
PHP version: 8.0.25

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

Steps to replicate it:

Go to Basic Setings and view Background Jobs.

The output of config.php file

config.php
<?php
$CONFIG = array (
  'filelocking.enabled' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\Memcache\\APCu',
  'datadirectory' => '/data',
  'instanceid' => 'xxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxx',
  'trusted_domains' => 
  array (
    0 => 'xxxxxxxxx',
    1 => 'xxxxxxxxx',
  ),
  'dbtype' => 'mysql',
  'version' => '25.0.2.3',
  'overwrite.cli.url' => 'https://xxxxxxxx',
  'dbname' => 'nextcloud',
  'dbhost' => 'xxxxxxx:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxxxxxx',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'tls',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'xxxxxx',
  'mail_domain' => 'gmail.com',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '587',
  'mail_smtpname' => 'xxxxxx@gmail.com',
  'mail_smtppassword' => 'xxxxxx',
  'memories.exiftool' => '/config/www/nextcloud/apps/memories/exiftool-bin/exiftool-amd64-musl',
  'updater.release.channel' => 'stable',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
    0 => 'xxxxxx Family',
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
);

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

error.log on /var/log/nginx is empty.

Here is the output of crontab -l

root@bf333f7f86f4:/var/log/php8# crontab -l

do daily/weekly/monthly maintenance

min hour day month weekday command

*/15 * * * * run-parts /etc/periodic/15min
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly

nextcloud cron

*/5 * * * * s6-setuidgid abc php -f /config/www/nextcloud/cron.php

#This is the important bit
sudo -u www-data crontab -e

*/5 * * * * php8.0 -f /config/www/nextcloud/cron.php

I am having exactly the same problem. Tried putting it in both root and www-data’s crontab; neither are working.

This is where things get a little fuzzy for me. There is no “user_data” user in my system. But there is an “abc” user. Also my php has a soft link that points to php8.

Use system cron service to call the cron.php file every 5 minutes. Recommended for all instances. The cron.php needs to be executed by the system user “abc”.

root@bf333f7f86f4:/usr/bin# which php
/usr/bin/php
root@bf333f7f86f4:/usr/bin# cd /usr/bin
root@bf333f7f86f4:/usr/bin# ls -l php*
lrwxrwxrwx 1 root root 13 Nov 29 10:46 php → /usr/bin/php8
-rwxr-xr-x 1 root root 8399160 Oct 26 09:04 php8
root@bf333f7f86f4:/usr/bin#

Do I need to create a “user_data” user? Based on the Background Jobs Section, CRON is executed as the “abc” user.

do me a favor - try running it on the command line with sudo -u abc php /config/www/nextcloud/cron.php. Mine hangs forever with no output; does yours?

Actually it returns within secs.

I tried it a second time and piped it to a file but the file is empty. So it appears to run, but there is no output.

The cron process isn’t normally running inside the docker container, so a workaround is needed. I can’t speak specifically about Unraid because I don’t use it, but I do it on Ubuntu by adding something like this in cron of the host OS to run every 5 minutes. Maybe you can do something similar.

docker exec -u www-data nextcloud-container php /path/to/nextcloud/cron.php

1 Like

Thank you. I will give that a try and let you know.

So I tried this from an unraid termial window.

docker exec -u abc nextcloud php /config/www/nextcloud/cron.php

It executed, but I don’t honestly know if it did anything. I substituted the “abc” user with ‘xx’ and it failed so I guess it’s using the "abc’ user. I guess I can add the above docker command to the main crontab for the unraid server and see what happens. I’m thinking the docker container for NextCloud must have to be edited to include the running of the crontab. I’m new to docker containers, so I may try to figure out if that is the answer. I can’t imagine that no one who is using Unraid has not run into this issue. There seems to be a lot of problems associated with Nextcloud and CRON.

It MUST be run as the web server user. This is usually the user www-data. If this is the official Docker container then that will be the case.

There’s an easy trick to tell if it worked. Set the background jobs back to AJAX. If the cron successfully runs, it changes the setting to cron automatically.

There’s really not, it’s just that Docker’s nature of one process per container (which in Nextcloud’s case is Apache) makes a workaround necessary. Either invoking it by an external means, or rebuilding the container with supervisord so the cron process runs in it natively.

Rebuilding with a native cron process isn’t hard if you want to try it, maybe just a little confusing for people who aren’t used to Docker. They have a Dockerfile that basically does it for you.

Since I’m going to stick with Unraid, it’s my intention to get much more familar with Docker. In the meantime, I’m sure I will struggle a bit.

So I tried this…I changed the background job to AJAX and ran the following command with is in the crontab for Nextcloud…

s6-setuidgid abc php -f /config/www/nextcloud/cron.php

It ran for a min or two. Afterwards, I refreshed the background job’s page and it switched to CRON.

Okay, good. So that’s the command you need. Now just automate it and you’re done.

I’m still seeing this message on the Background Jobs Page.

Last job execution ran 4 hours ago. Something seems wrong.

I assume this page should should the last successful CRON execution?

Yes, if the command was successful, it should flip over to cron, and shouldn’t have that warning for 10 minutes or so.

What is this abc user?

The “abc” user was already present in the crontab for the Nextcloud container. And it’s states on the Background Jobs Page, that CRON needs to be executed by the "abc"user.

Just to clarify, you are putting this in Unraid’s crontab, not the container?

Does Unraid use the official Docker image for Nextcloud or a customized one?

I believe the official one is Nextcloud-ffmpeg which is what I am not using. I installed this one…

docker pull Package nextcloud · GitHub

But I did notice there is a nextcloud-crontab container I can install from the app repository. I might give that a try.

Also, I just noticed that the cron entry I put in the Unraid crontab is gone. It must have be over-written when I rebooted my server this morning.

I tried the nextcloud-crontab app and it didn’t work. I still have the same “Last job execution ran 4 hours ago. Something seems wrong.” message on the Background Jobs page. I feel like I’m just spinning my wheels with this issue.