Skip to content

Commit 2b26b08

Browse files
authored
Merge pull request #61 from sebastianrakel/fix-postgres-online-check
Don't use wait for host port instead use pg_isready
2 parents 84e742c + 2d58f5a commit 2b26b08

File tree

2 files changed

+3
-32
lines changed

2 files changed

+3
-32
lines changed

openvoxdb/Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LABEL org.label-schema.maintainer="Voxpupuli Release Team <voxpupuli@groups.io>"
1616
org.label-schema.build-date="$build_date"
1717

1818
# Use netcat-openbsd to support IPv6 connectivity checks (netcat-traditional is IPv4 only)
19-
ARG PACKAGES="ca-certificates curl dnsutils netcat-openbsd dumb-init"
19+
ARG PACKAGES="ca-certificates curl dumb-init postgresql-client postgresql-client-common"
2020

2121
ARG LOGDIR
2222
ENV LOGDIR=${LOGDIR:-/opt/puppetlabs/server/data/puppetdb/logs}

openvoxdb/container-entrypoint.d/10-wait-for-hosts.sh

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ set -e
1616
# OPENVOXDB_POSTGRES_HOSTNAME Specified in Dockerfile, defaults to postgres
1717
# OPENVOXSERVER_HOSTNAME DNS name of puppetserver to wait on, defaults to puppet
1818

19-
2019
msg() {
2120
echo "($0) $1"
2221
}
@@ -26,43 +25,18 @@ error() {
2625
exit 1
2726
}
2827

29-
# Alpine as high as 3.9 seems to have failures reaching addresses sporadically
30-
# In local repro scenarios, performing a DNS lookup with dig increases reliability
31-
wait_for_host_name_resolution() {
32-
# host and dig are in the bind-tools Alpine package
33-
# k8s nodes may not be reachable with a ping
34-
# performing a dig prior to a host may help prime the cache in Alpine
35-
# https://github.com/Microsoft/opengcs/issues/303
36-
/wtfc.sh --timeout="${2}" --interval=1 --progress "dig $1 && host $1"
37-
# additionally log the DNS lookup information for diagnostic purposes
38-
NAME_RESOLVED=$?
39-
dig $1
40-
if [ $NAME_RESOLVED -ne 0 ]; then
41-
error "dependent service at $1 cannot be resolved or contacted"
42-
fi
43-
}
44-
45-
wait_for_host_port() {
46-
# -v verbose -w connect / final net read timeout -z scan and don't send data
47-
/wtfc.sh --timeout=${3} --interval=1 --progress "nc -v -w 1 -z '${1}' ${2}"
48-
if [ $? -ne 0 ]; then
49-
error "host $1:$2 does not appear to be listening"
50-
fi
51-
}
52-
5328
OPENVOXDB_WAITFORHOST_SECONDS=${OPENVOXDB_WAITFORHOST_SECONDS:-30}
5429
OPENVOXDB_WAITFORPOSTGRES_SECONDS=${OPENVOXDB_WAITFORPOSTGRES_SECONDS:-60}
5530
OPENVOXDB_WAITFORHEALTH_SECONDS=${OPENVOXDB_WAITFORHEALTH_SECONDS:-360}
5631
OPENVOXDB_POSTGRES_HOSTNAME="${OPENVOXDB_POSTGRES_HOSTNAME:-postgres}"
5732
OPENVOXSERVER_HOSTNAME="${OPENVOXSERVER_HOSTNAME:-puppet}"
5833
OPENVOXSERVER_PORT="${OPENVOXSERVER_PORT:-8140}"
5934

60-
# wait for postgres DNS
61-
wait_for_host_name_resolution $OPENVOXDB_POSTGRES_HOSTNAME $OPENVOXDB_WAITFORHOST_SECONDS
35+
# wait for postgres is ready
36+
/wtfc.sh --timeout="${OPENVOXDB_WAITFORHOST_SECONDS}" --interval=1 --progress "pg_isready -h ${OPENVOXDB_POSTGRES_HOSTNAME} --port '${OPENVOXDB_POSTGRES_PORT:-5432}'"
6237

6338
# wait for puppetserver DNS, then healthcheck
6439
if [ "$USE_OPENVOXSERVER" = true ]; then
65-
wait_for_host_name_resolution $OPENVOXSERVER_HOSTNAME $OPENVOXDB_WAITFORHOST_SECONDS
6640
HEALTH_COMMAND="curl --silent --fail --insecure 'https://${OPENVOXSERVER_HOSTNAME}:"${OPENVOXSERVER_PORT}"/status/v1/simple' | grep -q '^running$'"
6741
fi
6842

@@ -72,6 +46,3 @@ if [ -n "$HEALTH_COMMAND" ]; then
7246
error "Required health check failed"
7347
fi
7448
fi
75-
76-
# wait for postgres
77-
wait_for_host_port $OPENVOXDB_POSTGRES_HOSTNAME "${OPENVOXDB_POSTGRES_PORT:-5432}" $OPENVOXDB_WAITFORPOSTGRES_SECONDS

0 commit comments

Comments
 (0)