From 4db58df7ca95c56ea70b04666263b60f0c98bdf8 Mon Sep 17 00:00:00 2001 From: Sebastian Gaiser Date: Fri, 28 Aug 2026 17:11:20 +0200 Subject: [PATCH] Allow configuring the cron.php schedule The interval for cron.php is baked into the image at build time as */5 * * * * in /var/spool/cron/crontabs/www-data, and cron.sh offers no configuration at all. Changing it currently requires replacing the entrypoint and reimplementing the crond invocation downstream. Add NEXTCLOUD_CRON_SCHEDULE, honoured by /cron.sh. When set, the crontab is written to a writable directory and crond is pointed at it with -c, so the baked crontab stays in place and an image update cannot silently restore the old interval. When unset, -c receives busybox crond's own default directory, so the behaviour is unchanged. Rewriting the baked crontab in place is not an option because it is owned by root with mode 644 and therefore not writable when the container runs as an arbitrary user. Signed-off-by: Sebastian Gaiser --- 32/apache/cron.sh | 10 +++++++++- 32/fpm-alpine/cron.sh | 10 +++++++++- 32/fpm/cron.sh | 10 +++++++++- 33/apache/cron.sh | 10 +++++++++- 33/fpm-alpine/cron.sh | 10 +++++++++- 33/fpm/cron.sh | 10 +++++++++- 34/apache/cron.sh | 10 +++++++++- 34/fpm-alpine/cron.sh | 10 +++++++++- 34/fpm/cron.sh | 10 +++++++++- README.md | 13 +++++++++++++ docker-cron.sh | 10 +++++++++- 11 files changed, 103 insertions(+), 10 deletions(-) diff --git a/32/apache/cron.sh b/32/apache/cron.sh index b4cd9af65..b44a543c7 100755 --- a/32/apache/cron.sh +++ b/32/apache/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/32/fpm-alpine/cron.sh b/32/fpm-alpine/cron.sh index b4cd9af65..b44a543c7 100755 --- a/32/fpm-alpine/cron.sh +++ b/32/fpm-alpine/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/32/fpm/cron.sh b/32/fpm/cron.sh index b4cd9af65..b44a543c7 100755 --- a/32/fpm/cron.sh +++ b/32/fpm/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/33/apache/cron.sh b/33/apache/cron.sh index b4cd9af65..b44a543c7 100755 --- a/33/apache/cron.sh +++ b/33/apache/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/33/fpm-alpine/cron.sh b/33/fpm-alpine/cron.sh index b4cd9af65..b44a543c7 100755 --- a/33/fpm-alpine/cron.sh +++ b/33/fpm-alpine/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/33/fpm/cron.sh b/33/fpm/cron.sh index b4cd9af65..b44a543c7 100755 --- a/33/fpm/cron.sh +++ b/33/fpm/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/34/apache/cron.sh b/34/apache/cron.sh index b4cd9af65..b44a543c7 100755 --- a/34/apache/cron.sh +++ b/34/apache/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/34/fpm-alpine/cron.sh b/34/fpm-alpine/cron.sh index b4cd9af65..b44a543c7 100755 --- a/34/fpm-alpine/cron.sh +++ b/34/fpm-alpine/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/34/fpm/cron.sh b/34/fpm/cron.sh index b4cd9af65..b44a543c7 100755 --- a/34/fpm/cron.sh +++ b/34/fpm/cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs" diff --git a/README.md b/README.md index f3fedb5d3..b6bfb7f45 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ A safe home for all your data. Access & share your files, calendars, contacts, m - [Custom Data directory (`datadirectory`)](#custom-data-directory-datadirectory) - [Trusted domains (`trusted_domains`)](#trusted-domains-trusted_domains) - [Image specific](#image-specific) + - [Background jobs (`cron.php`)](#background-jobs-cronphp) - [Redis Memory Caching](#redis-memory-caching) - [E-mail (SMTP) Configuration](#e-mail-smtp-configuration) - [Object Storage (Primary Storage)](#object-storage-primary-storage) @@ -281,6 +282,18 @@ You might want to make sure the htaccess is up to date after each container upda - `NEXTCLOUD_INIT_HTACCESS` (not set by default) Set it to true to enable run `occ maintenance:update:htaccess` after container initialization. +### Background jobs (`cron.php`) + +The images ship a `/cron.sh` entrypoint that runs `php -f /var/www/html/cron.php` every 5 minutes via busybox `crond`. To run the background jobs less often, override the schedule with a standard five-field cron expression: + +- `NEXTCLOUD_CRON_SCHEDULE` (default: `*/5 * * * *`) Cron expression for `cron.php`. + +```console +$ docker run -d --volumes-from app -e NEXTCLOUD_CRON_SCHEDULE='*/30 * * * *' --entrypoint /cron.sh nextcloud +``` + +Note that Nextcloud's admin overview reports a warning once the last background job ran more than an hour ago, and jobs such as calendar event reminders are delayed by up to one interval. `TZ` applies to the schedule, so it is evaluated in the container's local time. + ### Redis Memory Caching To use Redis for memory caching as well as PHP session storage, specify the following values and also add a [Redis](https://hub.docker.com/_/redis/) container to your stack. See the [examples](https://github.com/nextcloud/docker/tree/master/.examples) for further instructions. diff --git a/docker-cron.sh b/docker-cron.sh index b4cd9af65..b44a543c7 100755 --- a/docker-cron.sh +++ b/docker-cron.sh @@ -1,4 +1,12 @@ #!/bin/sh set -eu -exec busybox crond -f -L /dev/stdout +crontabs=/var/spool/cron/crontabs + +if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then + crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs" + mkdir -p "$crontabs" + echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data" +fi + +exec busybox crond -f -L /dev/stdout -c "$crontabs"