From 6185478b21cec9e60ad8d74d1e6fb77f757476f7 Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Fri, 17 Apr 2026 15:17:15 +0200 Subject: [PATCH] allow to adjust the log level globally (nextcloud) Signed-off-by: Simon L. --- Containers/nextcloud/cron.sh | 5 ++++ Containers/nextcloud/entrypoint.sh | 34 +++++++++++++++++++---- Containers/nextcloud/healthcheck.sh | 4 +++ Containers/nextcloud/notify-all.sh | 4 +++ Containers/nextcloud/notify.sh | 4 +++ Containers/nextcloud/run-exec-commands.sh | 4 +++ Containers/nextcloud/start.sh | 12 ++++++-- Containers/nextcloud/supervisord.conf | 2 +- 8 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Containers/nextcloud/cron.sh b/Containers/nextcloud/cron.sh index 0b888279..c43822ca 100644 --- a/Containers/nextcloud/cron.sh +++ b/Containers/nextcloud/cron.sh @@ -1,4 +1,9 @@ #!/bin/bash + +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + wait_for_cron() { set -x while [ -n "$(pgrep -f /var/www/html/cron.php)" ]; do diff --git a/Containers/nextcloud/entrypoint.sh b/Containers/nextcloud/entrypoint.sh index 3c6f2c30..05050f24 100644 --- a/Containers/nextcloud/entrypoint.sh +++ b/Containers/nextcloud/entrypoint.sh @@ -10,6 +10,10 @@ directory_empty() { [ -z "$(ls -A "$1/")" ] } +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + run_upgrade_if_needed_due_to_app_update() { if php /var/www/html/occ status | grep maintenance | grep -q true; then php /var/www/html/occ maintenance:mode --off @@ -20,6 +24,14 @@ run_upgrade_if_needed_due_to_app_update() { fi } +NEXTCLOUD_LOG_LEVEL="$(case "$AIO_LOG_LEVEL" in + debug) printf '0' ;; + info) printf '1' ;; + warn) printf '2' ;; + error) printf '3' ;; +esac)" +export NEXTCLOUD_LOG_LEVEL + # Create cert bundle if env | grep -q NEXTCLOUD_TRUSTED_CERTIFICATES_; then @@ -75,7 +87,9 @@ if env | grep -q NEXTCLOUD_TRUSTED_CERTIFICATES_; then cat "$CERTIFICATE_BUNDLE" # Disable debug mode - set +x + if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x + fi fi # Adjust DATABASE_TYPE to by Nextcloud supported value @@ -222,7 +236,9 @@ if ! [ -f "$NEXTCLOUD_DATA_DIR/skip.update" ]; then if grep -q appstoreurl /var/www/html/config/config.php; then set -x APPSTORE_URL="$(grep appstoreurl /var/www/html/config/config.php | grep -oP 'https://.*v[0-9]+')" - set +x + if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x + fi fi # Default appstoreurl parameter in config.php defaults to 'https://apps.nextcloud.com/api/v1' so we check for the apps.json file stored in there CURL_STATUS="$(curl -LI "$APPSTORE_URL"/apps.json -o /dev/null -w '%{http_code}\n' -s)" @@ -289,7 +305,9 @@ if ! [ -f "$NEXTCLOUD_DATA_DIR/skip.update" ]; then "$SOURCE_LOCATION/custom_apps/" \ /var/www/html/custom_apps/ done - set +x + if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x + fi fi # Copy these from Nextcloud archive if they don't exist yet (i.e. new install) @@ -442,7 +460,7 @@ EOF # Apply log settings echo "Applying default settings..." mkdir -p /var/www/html/data - php /var/www/html/occ config:system:set loglevel --value="2" --type=integer + php /var/www/html/occ config:system:set loglevel --value="$NEXTCLOUD_LOG_LEVEL" --type=integer if [ "$NEXTCLOUD_LOG_TYPE" = "errorlog" ]; then php /var/www/html/occ config:system:set log_type --value="errorlog" php /var/www/html/occ config:system:set log_type_audit --value="errorlog" @@ -764,7 +782,9 @@ if [ "$COLLABORA_ENABLED" = 'yes' ]; then if echo "$COLLABORA_HOST" | grep -q "nextcloud-.*-collabora"; then COLLABORA_HOST="$NC_DOMAIN" fi - set +x + if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x + fi # Remove richdcoumentscode if it should be incorrectly installed if [ -d "/var/www/html/custom_apps/richdocumentscode" ]; then php /var/www/html/occ app:remove richdocumentscode @@ -885,7 +905,9 @@ if [ "$TALK_ENABLED" = 'yes' ]; then if [ -z "$TURN_DOMAIN" ]; then TURN_DOMAIN="$TALK_HOST" fi - set +x + if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x + fi if ! [ -d "/var/www/html/custom_apps/spreed" ]; then php /var/www/html/occ app:install spreed elif [ "$(php /var/www/html/occ config:app:get spreed enabled)" != "yes" ]; then diff --git a/Containers/nextcloud/healthcheck.sh b/Containers/nextcloud/healthcheck.sh index 54c79dca..25588d21 100644 --- a/Containers/nextcloud/healthcheck.sh +++ b/Containers/nextcloud/healthcheck.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + # Set a default value for POSTGRES_PORT if [ -z "$POSTGRES_PORT" ]; then POSTGRES_PORT=5432 diff --git a/Containers/nextcloud/notify-all.sh b/Containers/nextcloud/notify-all.sh index f4dfa0fd..137abd2e 100644 --- a/Containers/nextcloud/notify-all.sh +++ b/Containers/nextcloud/notify-all.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + if [[ "$EUID" = 0 ]]; then COMMAND=(sudo -E -u www-data php /var/www/html/occ) else diff --git a/Containers/nextcloud/notify.sh b/Containers/nextcloud/notify.sh index 2ac4ceac..5851c1ba 100644 --- a/Containers/nextcloud/notify.sh +++ b/Containers/nextcloud/notify.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + if [[ "$EUID" = 0 ]]; then COMMAND=(sudo -E -u www-data php /var/www/html/occ) else diff --git a/Containers/nextcloud/run-exec-commands.sh b/Containers/nextcloud/run-exec-commands.sh index e8066881..5f3a9744 100644 --- a/Containers/nextcloud/run-exec-commands.sh +++ b/Containers/nextcloud/run-exec-commands.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + # Wait until the apache container is ready while ! nc -z "$APACHE_HOST" "$APACHE_PORT"; do echo "Waiting for $APACHE_HOST to become available..." diff --git a/Containers/nextcloud/start.sh b/Containers/nextcloud/start.sh index a5f38534..822a6e21 100644 --- a/Containers/nextcloud/start.sh +++ b/Containers/nextcloud/start.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$AIO_LOG_LEVEL" = 'debug' ]; then + set -x +fi + # Set a default value for POSTGRES_PORT if [ -z "$POSTGRES_PORT" ]; then POSTGRES_PORT=5432 @@ -53,7 +57,9 @@ if ! [ -f "/dev-dri-group-was-added" ] && [ -n "$(find /dev -maxdepth 1 -mindept usermod -aG "$GROUP" www-data touch "/dev-dri-group-was-added" fi -set +x +if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x +fi # Check datadir permissions sudo -E -u www-data touch "$NEXTCLOUD_DATA_DIR/this-is-a-test-file" &>/dev/null @@ -170,6 +176,8 @@ if [ "$THIS_IS_AIO" = "true" ] && [ "$APACHE_PORT" = 443 ]; then sed -i "/^listen.allowed_clients/s/,$//" /usr/local/etc/php-fpm.d/www.conf grep listen.allowed_clients /usr/local/etc/php-fpm.d/www.conf fi -set +x +if [ "$AIO_LOG_LEVEL" != 'debug' ]; then + set +x +fi exec "$@" diff --git a/Containers/nextcloud/supervisord.conf b/Containers/nextcloud/supervisord.conf index ebe0b68f..5bf90ed0 100644 --- a/Containers/nextcloud/supervisord.conf +++ b/Containers/nextcloud/supervisord.conf @@ -6,7 +6,7 @@ pidfile=/var/run/supervisord/supervisord.pid childlogdir=/var/log/supervisord/ logfile_maxbytes=50MB ; maximum size of logfile before rotation logfile_backups=10 ; number of backed up logfiles -loglevel=error +loglevel=%(ENV_AIO_LOG_LEVEL)s user=root [program:php-fpm]