From 1231a36bc97341b9aca5accf0a97d692a903992f Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 16 Jul 2025 11:04:19 +0200 Subject: [PATCH] Create run --- .../etc/services.d/01-postgres-init/run | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ente/rootfs/etc/services.d/01-postgres-init/run diff --git a/ente/rootfs/etc/services.d/01-postgres-init/run b/ente/rootfs/etc/services.d/01-postgres-init/run new file mode 100644 index 000000000..2c46f076f --- /dev/null +++ b/ente/rootfs/etc/services.d/01-postgres-init/run @@ -0,0 +1,35 @@ +#!/usr/bin/with-contenv bashio +# shellcheck shell=bash +set -euo pipefail + +if bashio::config.true 'USE_EXTERNAL_DB'; then + # External DB; nothing to create here. + exit 0 +fi + +DB_USER="$(bashio::config 'DB_USERNAME')" +DB_PASS="$(bashio::config 'DB_PASSWORD')" +DB_NAME="$(bashio::config 'DB_DATABASE_NAME')" + +bashio::log.info "Postgres-init: waiting for local Postgres..." +until pg_isready -q -h 127.0.0.1 -p 5432 -U postgres; do + sleep 1 +done + +bashio::log.info "Postgres-init: creating role/database if missing..." +# psql search_path safe quoting using dollar-quoted strings for password +psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -p 5432 -U postgres <