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-
2019msg () {
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-
5328OPENVOXDB_WAITFORHOST_SECONDS=${OPENVOXDB_WAITFORHOST_SECONDS:- 30}
5429OPENVOXDB_WAITFORPOSTGRES_SECONDS=${OPENVOXDB_WAITFORPOSTGRES_SECONDS:- 60}
5530OPENVOXDB_WAITFORHEALTH_SECONDS=${OPENVOXDB_WAITFORHEALTH_SECONDS:- 360}
5631OPENVOXDB_POSTGRES_HOSTNAME=" ${OPENVOXDB_POSTGRES_HOSTNAME:- postgres} "
5732OPENVOXSERVER_HOSTNAME=" ${OPENVOXSERVER_HOSTNAME:- puppet} "
5833OPENVOXSERVER_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
6439if [ " $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$'"
6741fi
6842
@@ -72,6 +46,3 @@ if [ -n "$HEALTH_COMMAND" ]; then
7246 error " Required health check failed"
7347 fi
7448fi
75-
76- # wait for postgres
77- wait_for_host_port $OPENVOXDB_POSTGRES_HOSTNAME " ${OPENVOXDB_POSTGRES_PORT:- 5432} " $OPENVOXDB_WAITFORPOSTGRES_SECONDS
0 commit comments