#!/usr/bin/env bash # Runs PostgreSQL (through the stock postgres entrypoint) and the peo4c bridge # side by side, and stops the container when either of them exits. set -euo pipefail if [ "${1:-}" != "postgres" ]; then exec docker-entrypoint.sh "$@" fi export PEO4C_PG_DATABASE="${PEO4C_PG_DATABASE:-${POSTGRES_DB:-${POSTGRES_USER:-postgres}}}" docker-entrypoint.sh "$@" & pg_pid=$! cd /opt/peo4c/bridge gosu postgres python3 -m peo4c & bridge_pid=$! shutdown() { kill -TERM "$bridge_pid" 2>/dev/null || true kill -TERM "$pg_pid" 2>/dev/null || true } trap shutdown TERM INT # Wait until one of the two processes exits, then stop the other one too. set +e wait -n "$pg_pid" "$bridge_pid" status=$? shutdown wait "$pg_pid" 2>/dev/null exit "$status"