#!/usr/bin/env bash set -euo pipefail run_as_postgres() { if id postgres >/dev/null 2>&1; then if command -v gosu >/dev/null 2>&1; then gosu postgres "$@" elif command -v su-exec >/dev/null 2>&1; then su-exec postgres "$@" else su postgres -s /bin/sh -c "$(printf '%q ' "$@")" fi else "$@" fi } echo "[boot] start redis" redis-server --bind 127.0.0.1 --port 6379 --daemonize yes echo "[boot] init/start postgres" mkdir -p "${PGDATA}" /tmp if id postgres >/dev/null 2>&1; then chown -R postgres:postgres "${PGDATA}" || true fi if [ ! -s "${PGDATA}/PG_VERSION" ]; then run_as_postgres initdb -D "${PGDATA}" >/dev/null fi # Place Unix socket under /tmp to avoid missing /run/postgresql in HF runtime. run_as_postgres pg_ctl -D "${PGDATA}" \ -o "-c listen_addresses=127.0.0.1 -c port=5432 -c unix_socket_directories=/tmp" \ -w start # Upsert DB role. run_as_postgres psql -h 127.0.0.1 -p 5432 -v ON_ERROR_STOP=1 --username postgres --dbname postgres <