From 0c7ef56635492a2d1be6eda74b7e63a22434b30b Mon Sep 17 00:00:00 2001 From: Roland Vet Date: Tue, 6 Apr 2021 12:56:35 +0200 Subject: [PATCH] Replace crond with a while loop. Adding the cron command to /var/spool/cron/crontabs/www-data assumes that cron, and by extension the nextcloud app, is run as 'www-data'. 'crond' cannot be used with: exec "echo \"*/%%CRONTAB_INT%% * * * * php -f /var/www/html/cron.php\" | crontab - && crond -f -l 0 -L /dev/stdout" because that assumes the uid used matches a entry in '/etc/passwd'. Signed-off-by: Roland Vet --- Dockerfile-alpine.template | 3 +-- Dockerfile-debian.template | 5 +---- docker-cron.sh | 5 ++++- update.sh | 5 ++++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index 4d05f14d..b7afed9c 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -7,8 +7,7 @@ RUN set -ex; \ rsync \ ; \ \ - rm /var/spool/cron/crontabs/root; \ - echo '*/%%CRONTAB_INT%% * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data + rm /var/spool/cron/crontabs/root # install the PHP extensions we need # see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template index e6c48d54..26b00dbb 100644 --- a/Dockerfile-debian.template +++ b/Dockerfile-debian.template @@ -10,10 +10,7 @@ RUN set -ex; \ busybox-static \ libldap-common \ ; \ - rm -rf /var/lib/apt/lists/*; \ - \ - mkdir -p /var/spool/cron/crontabs; \ - echo '*/%%CRONTAB_INT%% * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data + rm -rf /var/lib/apt/lists/* # install the PHP extensions we need # see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html diff --git a/docker-cron.sh b/docker-cron.sh index 4dfa4118..d38ea81f 100755 --- a/docker-cron.sh +++ b/docker-cron.sh @@ -1,4 +1,7 @@ #!/bin/sh set -eu -exec busybox crond -f -l 0 -L /dev/stdout +while [ 1 ]; do + (php -f /var/www/html/cron.php &); + sleep %%CRONTAB_INT%%m; +done diff --git a/update.sh b/update.sh index e293a800..bda4bba5 100755 --- a/update.sh +++ b/update.sh @@ -111,7 +111,6 @@ function create_variant() { s/%%MEMCACHED_VERSION%%/'"${pecl_versions[memcached]}"'/g; s/%%REDIS_VERSION%%/'"${pecl_versions[redis]}"'/g; s/%%IMAGICK_VERSION%%/'"${pecl_versions[imagick]}"'/g; - s/%%CRONTAB_INT%%/'"$crontabInt"'/g; ' "$dir/Dockerfile" case "$phpVersion" in @@ -132,6 +131,10 @@ function create_variant() { for name in entrypoint cron; do cp "docker-$name.sh" "$dir/$name.sh" done + # Replace the variable. + sed -ri -e ' + s/%%CRONTAB_INT%%/'"$crontabInt"'/g; + ' "$dir/cron.sh" # Copy the upgrade.exclude cp upgrade.exclude "$dir/"