Files
hassio-addons/ente/rootfs/etc/services.d/00-postgres/run
2025-07-16 13:46:38 +00:00

40 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
# Create folder structure
mkdir -p /run/postgresql
chown postgres:postgres /run/postgresql
chmod 775 /run/postgresql
# Persistent location
PGDATA="${PGDATA:-/config/postgres-data}"
export PGDATA
# Create and secure PGDATA
mkdir -p "$PGDATA"
chown -R postgres:postgres "$PGDATA"
chmod 0700 "$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..."
# Alpines initdb runs as the postgres user
su - postgres -c "$INITDB -D $PGDATA"
fi
exec su - postgres -c "$POSTGRES -D $PGDATA -c listen_addresses='127.0.0.1'" & \
bashio::log.info "Starting Postgres (127.0.0.1:5432)..."