From 2d58f5a15b0a1e2e0bf7e7266ec8a6a81c654b31 Mon Sep 17 00:00:00 2001 From: Sebastian Rakel Date: Sun, 28 Dec 2025 17:39:11 +0100 Subject: [PATCH] Don't use wait for host port instead use pg_isready --- openvoxdb/Containerfile | 2 +- .../10-wait-for-hosts.sh | 33 ++----------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/openvoxdb/Containerfile b/openvoxdb/Containerfile index af92329..951f5f0 100644 --- a/openvoxdb/Containerfile +++ b/openvoxdb/Containerfile @@ -16,7 +16,7 @@ LABEL org.label-schema.maintainer="Voxpupuli Release Team " org.label-schema.build-date="$build_date" # Use netcat-openbsd to support IPv6 connectivity checks (netcat-traditional is IPv4 only) -ARG PACKAGES="ca-certificates curl dnsutils netcat-openbsd dumb-init" +ARG PACKAGES="ca-certificates curl dumb-init postgresql-client postgresql-client-common" ARG LOGDIR ENV LOGDIR=${LOGDIR:-/opt/puppetlabs/server/data/puppetdb/logs} diff --git a/openvoxdb/container-entrypoint.d/10-wait-for-hosts.sh b/openvoxdb/container-entrypoint.d/10-wait-for-hosts.sh index 4985d4c..5ec7332 100755 --- a/openvoxdb/container-entrypoint.d/10-wait-for-hosts.sh +++ b/openvoxdb/container-entrypoint.d/10-wait-for-hosts.sh @@ -16,7 +16,6 @@ set -e # OPENVOXDB_POSTGRES_HOSTNAME Specified in Dockerfile, defaults to postgres # OPENVOXSERVER_HOSTNAME DNS name of puppetserver to wait on, defaults to puppet - msg() { echo "($0) $1" } @@ -26,30 +25,6 @@ error() { exit 1 } -# Alpine as high as 3.9 seems to have failures reaching addresses sporadically -# In local repro scenarios, performing a DNS lookup with dig increases reliability -wait_for_host_name_resolution() { - # host and dig are in the bind-tools Alpine package - # k8s nodes may not be reachable with a ping - # performing a dig prior to a host may help prime the cache in Alpine - # https://github.com/Microsoft/opengcs/issues/303 - /wtfc.sh --timeout="${2}" --interval=1 --progress "dig $1 && host $1" - # additionally log the DNS lookup information for diagnostic purposes - NAME_RESOLVED=$? - dig $1 - if [ $NAME_RESOLVED -ne 0 ]; then - error "dependent service at $1 cannot be resolved or contacted" - fi -} - -wait_for_host_port() { - # -v verbose -w connect / final net read timeout -z scan and don't send data - /wtfc.sh --timeout=${3} --interval=1 --progress "nc -v -w 1 -z '${1}' ${2}" - if [ $? -ne 0 ]; then - error "host $1:$2 does not appear to be listening" - fi -} - OPENVOXDB_WAITFORHOST_SECONDS=${OPENVOXDB_WAITFORHOST_SECONDS:-30} OPENVOXDB_WAITFORPOSTGRES_SECONDS=${OPENVOXDB_WAITFORPOSTGRES_SECONDS:-60} OPENVOXDB_WAITFORHEALTH_SECONDS=${OPENVOXDB_WAITFORHEALTH_SECONDS:-360} @@ -57,12 +32,11 @@ OPENVOXDB_POSTGRES_HOSTNAME="${OPENVOXDB_POSTGRES_HOSTNAME:-postgres}" OPENVOXSERVER_HOSTNAME="${OPENVOXSERVER_HOSTNAME:-puppet}" OPENVOXSERVER_PORT="${OPENVOXSERVER_PORT:-8140}" -# wait for postgres DNS -wait_for_host_name_resolution $OPENVOXDB_POSTGRES_HOSTNAME $OPENVOXDB_WAITFORHOST_SECONDS +# wait for postgres is ready +/wtfc.sh --timeout="${OPENVOXDB_WAITFORHOST_SECONDS}" --interval=1 --progress "pg_isready -h ${OPENVOXDB_POSTGRES_HOSTNAME} --port '${OPENVOXDB_POSTGRES_PORT:-5432}'" # wait for puppetserver DNS, then healthcheck if [ "$USE_OPENVOXSERVER" = true ]; then - wait_for_host_name_resolution $OPENVOXSERVER_HOSTNAME $OPENVOXDB_WAITFORHOST_SECONDS HEALTH_COMMAND="curl --silent --fail --insecure 'https://${OPENVOXSERVER_HOSTNAME}:"${OPENVOXSERVER_PORT}"/status/v1/simple' | grep -q '^running$'" fi @@ -72,6 +46,3 @@ if [ -n "$HEALTH_COMMAND" ]; then error "Required health check failed" fi fi - -# wait for postgres -wait_for_host_port $OPENVOXDB_POSTGRES_HOSTNAME "${OPENVOXDB_POSTGRES_PORT:-5432}" $OPENVOXDB_WAITFORPOSTGRES_SECONDS