From 246d4f4696acbb4568ae61087a69d6f2a609a7b9 Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Wed, 3 Dec 2025 17:05:10 +0100 Subject: [PATCH] minor fixes --- postgresql/config/config.env | 3 ++- postgresql/config/init.sql | 5 +++++ postgresql/config/upgrade.sh | 4 ++++ postgresql/postgresql-backup.container | 2 ++ postgresql/postgresql-init.container | 7 +++++++ postgresql/postgresql-server.container | 6 ++++++ postgresql/postgresql-upgrade.container | 5 +++++ 7 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 postgresql/config/init.sql diff --git a/postgresql/config/config.env b/postgresql/config/config.env index 7cd2fe1..9b7f360 100644 --- a/postgresql/config/config.env +++ b/postgresql/config/config.env @@ -3,6 +3,7 @@ POSTGRES_PASSWORD=postgres POSTGRES_DB=postgres POSTGRES_HOST_AUTH_METHOD=scram-sha-256 POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256 +POSTGRES_ARGS=-h 127.0.0.1 PGPORT=5432 -PG_MAJOR=14 +PG_MAJOR=17 POSTGRES_BACKUP_RETENTION=7 diff --git a/postgresql/config/init.sql b/postgresql/config/init.sql new file mode 100644 index 0000000..b311c0a --- /dev/null +++ b/postgresql/config/init.sql @@ -0,0 +1,5 @@ +-- Initialization script for Nextcloud database and user +CREATE USER nextcloud WITH PASSWORD 'nextcloud'; +CREATE DATABASE nextcloud OWNER nextcloud; +GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud; +ALTER ROLE nextcloud SET client_encoding TO 'utf8'; diff --git a/postgresql/config/upgrade.sh b/postgresql/config/upgrade.sh index d1d3d8f..394212a 100755 --- a/postgresql/config/upgrade.sh +++ b/postgresql/config/upgrade.sh @@ -144,6 +144,10 @@ fi unset PGPASSWORD docker_temp_server_stop +# Remove old data directory +echo "Removing old PostgreSQL data directory: ${SOURCE_PGDATA}" +rm -rf "${SOURCE_PGDATA}" + # Clean up lock files rm -f "${SOURCE_PGDATA}/upgrade_in_progress.lock" echo "PostgreSQL upgrade from version ${SOURCE_MAJOR_VERSION} to ${TARGET_MAJOR_VERSION} completed successfully." diff --git a/postgresql/postgresql-backup.container b/postgresql/postgresql-backup.container index a834879..fdfb895 100644 --- a/postgresql/postgresql-backup.container +++ b/postgresql/postgresql-backup.container @@ -19,6 +19,8 @@ EnvironmentFile=/etc/quadlets/postgresql/config.env # Use a custom backup script Entrypoint=/usr/local/bin/backup.sh + +# No need for root privileges User=postgres # Volume mounts diff --git a/postgresql/postgresql-init.container b/postgresql/postgresql-init.container index 18bf6cb..9126b5c 100644 --- a/postgresql/postgresql-init.container +++ b/postgresql/postgresql-init.container @@ -29,9 +29,16 @@ EnvironmentFile=/etc/quadlets/postgresql/config.env # Use our entrypoint script to initialize the database Entrypoint=/usr/local/bin/init.sh +# Set PostgreSQL command line arguments +Exec=${POSTGRES_ARGS} + +# No need for root privileges +User=postgres + # Volume mounts Volume=/var/lib/quadlets/postgresql:/var/lib/postgresql:z Volume=/etc/quadlets/postgresql/init.sh:/usr/local/bin/init.sh:z,ro +Volume=/etc/quadlets/postgresql/init.sql:/docker-entrypoint-initdb.d/init.sql:z,ro [Service] Restart=no diff --git a/postgresql/postgresql-server.container b/postgresql/postgresql-server.container index efc3d35..dcdc248 100644 --- a/postgresql/postgresql-server.container +++ b/postgresql/postgresql-server.container @@ -34,6 +34,12 @@ EnvironmentFile=/etc/quadlets/postgresql/config.env # Volume mounts Volume=/var/lib/quadlets/postgresql:/var/lib/postgresql:z +# Set PostgreSQL command line arguments +Exec=${POSTGRES_ARGS} + +# No need for root privileges +User=postgres + # Health check HealthCmd=pg_isready -U $POSTGRES_USER -d $POSTGRES_DB -p $PGPORT HealthInterval=30s diff --git a/postgresql/postgresql-upgrade.container b/postgresql/postgresql-upgrade.container index 9ac0a94..70e4295 100644 --- a/postgresql/postgresql-upgrade.container +++ b/postgresql/postgresql-upgrade.container @@ -27,8 +27,13 @@ EnvironmentFile=/etc/quadlets/postgresql/config.env # Use our entrypoint script to upgrade the database Entrypoint=/usr/local/bin/upgrade.sh + +# No need for root privileges User=postgres +# Set PostgreSQL command line arguments +Exec=${POSTGRES_ARGS} + # Volume mounts Volume=/var/lib/quadlets/postgresql:/var/lib/postgresql:z Volume=/etc/quadlets/postgresql/upgrade.sh:/usr/local/bin/upgrade.sh:z,ro