mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-15 17:08:19 +01:00
33 lines
947 B
Plaintext
33 lines
947 B
Plaintext
#!/usr/bin/with-contenv bashio
|
||
# shellcheck shell=bash
|
||
set -euo pipefail
|
||
|
||
if bashio::config.true 'USE_EXTERNAL_DB'; then
|
||
bashio::log.info "External DB requested; skipping internal Postgres service."
|
||
exit 0
|
||
fi
|
||
|
||
# Persistent location
|
||
PGDATA="${PGDATA:-/config/postgres-data}"
|
||
export PGDATA
|
||
|
||
mkdir -p "${PGDATA}"
|
||
chown -R postgres:postgres "${PGDATA}"
|
||
|
||
INITDB="$(command -v initdb || echo /usr/bin/initdb)"
|
||
POSTGRES="$(command -v postgres || echo /usr/bin/postgres)"
|
||
|
||
if [[ ! -x "$INITDB" || ! -x "$POSTGRES" ]]; then
|
||
bashio::log.error "PostgreSQL binaries not found."
|
||
exit 1
|
||
fi
|
||
|
||
if [[ ! -s "${PGDATA}/PG_VERSION" ]]; then
|
||
bashio::log.info "Initializing Postgres data directory..."
|
||
# Alpine’s initdb runs as the postgres user
|
||
s6-setuidgid postgres "$INITDB" -D "${PGDATA}"
|
||
fi
|
||
|
||
bashio::log.info "Starting Postgres (127.0.0.1:5432)..."
|
||
exec s6-setuidgid postgres "$POSTGRES" -D "${PGDATA}" -c listen_addresses='127.0.0.1'
|