Skip to content

Commit

Permalink
make database connections persistant
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed Jul 23, 2023
1 parent b076d5e commit ac22f8a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
9 changes: 9 additions & 0 deletions Containers/nextcloud/config/postgresql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
$CONFIG = array (
'dbuser' => 'oc_' . getenv('POSTGRES_USER'),
'dbpassword' => getenv('POSTGRES_PASSWORD'),
'db_name' => getenv('POSTGRES_DB'),
'dbdriveroptions' => array(
\PDO::ATTR_PERSISTENT => 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:/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
7 changes: 0 additions & 7 deletions Containers/postgresql/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ fi

# Modify postgresql.conf
if [ -f "/var/lib/postgresql/data/postgresql.conf" ]; then
echo "Setting max connections..."
MEMORY=$(awk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
MAX_CONNECTIONS=$((MEMORY/50+3))
if [ -n "$MAX_CONNECTIONS" ]; then
sed -i "s|^max_connections =.*|max_connections = $MAX_CONNECTIONS|" "/var/lib/postgresql/data/postgresql.conf"
fi

# Modify conf
if grep -q "#log_checkpoints" /var/lib/postgresql/data/postgresql.conf; then
sed -i 's|#log_checkpoints.*|log_checkpoints = off|' /var/lib/postgresql/data/postgresql.conf
Expand Down

0 comments on commit ac22f8a

Please sign in to comment.