Skip to content

Commit

Permalink
Merge pull request #3021 from nextcloud/enh/noid/persistant-db-connec…
Browse files Browse the repository at this point in the history
…tions

make database connections persistant
  • Loading branch information
szaimen authored Jul 28, 2023
2 parents 4ac2dbd + 42b065b commit 828190e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 7 additions & 0 deletions Containers/nextcloud/config/postgresql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$CONFIG = array (
'dbuser' => 'oc_' . getenv('POSTGRES_USER'),
'dbpassword' => getenv('POSTGRES_PASSWORD'),
'db_name' => getenv('POSTGRES_DB'),
'dbpersistent' => true,
);
12 changes: 1 addition & 11 deletions Containers/nextcloud/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ while ! sudo -u www-data nc -z "$POSTGRES_HOST" 5432; do
sleep 5
done

# Use the correct Postgres username
POSTGRES_USER="oc_$POSTGRES_USER"
export POSTGRES_USER

# Fix false database connection on old instances
# Wait for database to actually start
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
Expand Down

0 comments on commit 828190e

Please sign in to comment.