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 <