Update 99-run.sh

This commit is contained in:
Alexandre
2025-07-16 11:01:33 +02:00
committed by GitHub
parent 15001165e3
commit 8f530d391a

View File

@@ -41,29 +41,27 @@ if bashio::config.true 'USE_EXTERNAL_DB'; then
DB_NAME="$(bashio::config 'DB_DATABASE_NAME')" DB_NAME="$(bashio::config 'DB_DATABASE_NAME')"
fi fi
bashio::log.info "Bootstrapping Postgres cluster…" bashio::log.info "Postgres-init: waiting for local Postgres..."
until pg_isready -q -h 127.0.0.1 -p 5432 -U postgres; do
# Wait for postgres service (localhost)
until pg_isready -q -h localhost -p 5432 -U postgres; do
bashio::log.info "Waiting for Postgres to accept connections…"
sleep 1 sleep 1
done
bashio::log.info "Creating role + database if needed…" bashio::log.info "Postgres-init: creating role/database if missing..."
su - postgres -c psql <<SQL # 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 <<SQL
DO \$\$ DO \$\$
BEGIN BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${DB_USER}') THEN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}') THEN
CREATE ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS}'; EXECUTE 'CREATE ROLE ${DB_USER} LOGIN PASSWORD ''' || replace('${DB_PASS}','''','''''') || '''';
END IF; END IF;
IF NOT EXISTS (SELECT FROM pg_database WHERE datname = '${DB_NAME}') THEN IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}') THEN
CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}; EXECUTE 'CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}';
END IF; END IF;
END END
\$\$; \$\$;
SQL SQL
bashio::log.info "Internal Postgres ready."
done bashio::log.info "Postgres-init: done."
################# #################
# Minio startup # # Minio startup #