Nextcloud Background Jobs - joefidler/joefidler.github.io GitHub Wiki

Nextcloud needs a bit of regular maintenance and uses a background job for that. We can setup a containerized cron-job to start that job. After installing this cron-job make sure to tell Nextcloud to use it via Settings - Administration - Basic Settings, and select Cron for Background Jobs.

See here for more info on background jobs: https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html#cron

External storage

Nextcloud relies on background jobs to sync up external storages (DropBox, S3, OneDrive, Google Drive) - quoting the manual "Especially when using the Activity App or external storages, where new files are added, updated or deleted one of the two methods below should be preferred."

Creating the cron-job

The cron-job executes an already existing cron.sh script provided in the Nextcloud container. We create a container for that script. In the command we overwrite the default ENTRYPOINT of the image, in this case to run our cron.sh.

podman pull docker.io/library/nextcloud:fpm-alpine

podman run \
-d --restart=always --pod=nextcloud_pod \
-v ~/containers/nextcloud/html:/var/www/html:z \
--entrypoint=/cron.sh \
--name=nextcloud_pod-cron \ 
docker.io/library/nextcloud:fpm-alpine

What does this do?

cron.sh basically creates a cron job for Nextcloud's chron.php

$ podman logs nextcloud_pod-cron
crond: crond (busybox 1.32.1) started, log level 0
crond: user:www-data entry:*/5 * * * * php -f /var/www/html/cron.php
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: user:www-data entry:*/5 * * * * php -f /var/www/html/cron.php
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: wakeup dt=45
crond: file www-data:
crond:  line php -f /var/www/html/cron.php
crond:  job: 0 php -f /var/www/html/cron.php
crond: child running /bin/ash
crond: USER www-data pid   2 cmd php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=50
crond: file www-data:
crond:  line php -f /var/www/html/cron.php