Skip to content

Commit 4db58df

Browse files
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 <sebastiangaiser@users.noreply.github.com>
1 parent d51ecd0 commit 4db58df

11 files changed

Lines changed: 103 additions & 10 deletions

File tree

32/apache/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

32/fpm-alpine/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

32/fpm/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

33/apache/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

33/fpm-alpine/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

33/fpm/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

34/apache/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

34/fpm-alpine/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

34/fpm/cron.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
exec busybox crond -f -L /dev/stdout
4+
crontabs=/var/spool/cron/crontabs
5+
6+
if [ -n "${NEXTCLOUD_CRON_SCHEDULE:-}" ]; then
7+
crontabs="${TMPDIR:-/tmp}/nextcloud-crontabs"
8+
mkdir -p "$crontabs"
9+
echo "$NEXTCLOUD_CRON_SCHEDULE php -f /var/www/html/cron.php" > "$crontabs/www-data"
10+
fi
11+
12+
exec busybox crond -f -L /dev/stdout -c "$crontabs"

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ A safe home for all your data. Access & share your files, calendars, contacts, m
3434
- [Custom Data directory (`datadirectory`)](#custom-data-directory-datadirectory)
3535
- [Trusted domains (`trusted_domains`)](#trusted-domains-trusted_domains)
3636
- [Image specific](#image-specific)
37+
- [Background jobs (`cron.php`)](#background-jobs-cronphp)
3738
- [Redis Memory Caching](#redis-memory-caching)
3839
- [E-mail (SMTP) Configuration](#e-mail-smtp-configuration)
3940
- [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
281282

282283
- `NEXTCLOUD_INIT_HTACCESS` (not set by default) Set it to true to enable run `occ maintenance:update:htaccess` after container initialization.
283284

285+
### Background jobs (`cron.php`)
286+
287+
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:
288+
289+
- `NEXTCLOUD_CRON_SCHEDULE` (default: `*/5 * * * *`) Cron expression for `cron.php`.
290+
291+
```console
292+
$ docker run -d --volumes-from app -e NEXTCLOUD_CRON_SCHEDULE='*/30 * * * *' --entrypoint /cron.sh nextcloud
293+
```
294+
295+
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.
296+
284297
### Redis Memory Caching
285298

286299
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.

0 commit comments

Comments
 (0)