From 369226f9dfb62cacf81aa82d11fdfe1f43ba533d Mon Sep 17 00:00:00 2001 From: Simon L Date: Thu, 10 Aug 2023 10:38:27 +0200 Subject: [PATCH] Revert "https://github.com/nextcloud/all-in-one/pull/3021" partially Signed-off-by: Simon L --- Containers/nextcloud/config/postgresql.config.php | 7 ------- Containers/nextcloud/entrypoint.sh | 3 +++ Containers/nextcloud/start.sh | 12 +++++++++++- 3 files changed, 14 insertions(+), 8 deletions(-) delete mode 100644 Containers/nextcloud/config/postgresql.config.php diff --git a/Containers/nextcloud/config/postgresql.config.php b/Containers/nextcloud/config/postgresql.config.php deleted file mode 100644 index f086b297..00000000 --- a/Containers/nextcloud/config/postgresql.config.php +++ /dev/null @@ -1,7 +0,0 @@ - 'oc_' . getenv('POSTGRES_USER'), - 'dbpassword' => getenv('POSTGRES_PASSWORD'), - 'db_name' => getenv('POSTGRES_DB'), - 'dbpersistent' => true, -); diff --git a/Containers/nextcloud/entrypoint.sh b/Containers/nextcloud/entrypoint.sh index 64188892..e2775f56 100644 --- a/Containers/nextcloud/entrypoint.sh +++ b/Containers/nextcloud/entrypoint.sh @@ -482,6 +482,9 @@ php /var/www/html/occ config:system:set overwrite.cli.url --value="https://$NC_D php /var/www/html/occ config:system:set htaccess.RewriteBase --value="/" php /var/www/html/occ maintenance:update:htaccess +# Apply dbpersistent setting in order to fix too many db connections +php /var/www/html/occ config:system:set dbpersistent --value=true --type=bool + # Disallow creating local external storages when nothing was mounted if [ -z "$NEXTCLOUD_MOUNT" ]; then php /var/www/html/occ config:system:set files_external_allow_create_new_local --type=bool --value=false diff --git a/Containers/nextcloud/start.sh b/Containers/nextcloud/start.sh index 95c0af90..b990d6c5 100644 --- a/Containers/nextcloud/start.sh +++ b/Containers/nextcloud/start.sh @@ -6,13 +6,23 @@ while ! sudo -u www-data nc -z "$POSTGRES_HOST" 5432; do sleep 5 done -# Wait for database to actually start +# Use the correct Postgres username +POSTGRES_USER="oc_$POSTGRES_USER" +export POSTGRES_USER + +# Fix false database connection on old instances if [ -f "/var/www/html/config/config.php" ]; then sleep 2 while ! sudo -u www-data psql -d "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB" -c "select now()"; do echo "Waiting for the database to start..." sleep 5 done + if [ "$POSTGRES_USER" = "oc_nextcloud" ] && [ "$POSTGRES_DB" = "nextcloud_database" ] && echo "$POSTGRES_PASSWORD" | grep -q '^[a-z0-9]\+$'; then + # This was introduced with https://github.com/nextcloud/all-in-one/pull/218 + sed -i "s|'dbuser'.*=>.*$|'dbuser' => '$POSTGRES_USER',|" /var/www/html/config/config.php + sed -i "s|'dbpassword'.*=>.*$|'dbpassword' => '$POSTGRES_PASSWORD',|" /var/www/html/config/config.php + sed -i "s|'db_name'.*=>.*$|'db_name' => '$POSTGRES_DB',|" /var/www/html/config/config.php + fi fi # Trust additional Cacerts, if the user provided $TRUSTED_CACERTS_DIR