postgresql-citus-patroni-image/ep.sh
2024-06-23 11:54:59 +03:00

58 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
set -ef
c="${1##*/}"
case "$c" in
patroni | postgres ) ;;
* )
unset WITH_CITUS CITUS_PGPASSWORD
exec "$@"
;;
esac
PATH=$(printf '%s' "${PATH}" | sed -zE 's#(^|:)/usr/local/sbin($|:)##')
PATH="/usr/local/sbin:${PATH}"
export PATH
## quirk: Citus requires PGPASSWORD to be set however PostgreSQL flushes it
if [ "${WITH_CITUS}" = 1 ] ; then
while [ -z "${CITUS_PGPASSWORD+1}" ] ; do
[ -n "${PGPASSWORD+1}" ] || break
CITUS_PGPASSWORD=${PGPASSWORD}
break ; done
while [ -z "${CITUS_PGPASSWORD+1}" ] ; do
[ -n "${POSTGRES_PASSWORD_FILE}" ] || break
[ -f "${POSTGRES_PASSWORD_FILE}" ] || break
CITUS_PGPASSWORD=$(cat "${POSTGRES_PASSWORD_FILE}")
break ; done
while [ -z "${CITUS_PGPASSWORD+1}" ] ; do
[ -n "${POSTGRES_PASSWORD+1}" ] || break
CITUS_PGPASSWORD=${POSTGRES_PASSWORD}
break ; done
if [ -n "${CITUS_PGPASSWORD+1}" ] ; then
export CITUS_PGPASSWORD
fi
else
unset CITUS_PGPASSWORD
fi
unset WITH_CITUS
set +e
chown -h postgres:postgres "${PGHOME}"
[ -d "${PGDATA}" ] || install -d -o postgres -g postgres -m 1755 "${PGDATA}"
chown -h postgres:postgres "${PGDATA}"
set -e
if [ "$c" = postgres ] ; then
exec dumb-init docker-entrypoint.sh "$@"
fi
if [ "$(id -u)" != 0 ] ; then
exec dumb-init "$@"
fi
exec dumb-run-as.sh postgres dumb-init "$@"