@@ -6,6 +6,14 @@ port=9999
66socket_dir=" /tmp/pgmoon-test-socket"
77
88postgres_version=${DOCKER_POSTGRES_VERSION:- latest}
9+ startup_timeout=15
10+
11+ function fail_with_logs {
12+ echo " $( tput setaf 1) ERROR: $1 $( tput sgr0) " >&2
13+ echo " $( tput setaf 3) Docker container logs:$( tput sgr0) " >&2
14+ docker logs pgmoon-test 2>&1 | tail -100 >&2
15+ exit 1
16+ }
917
1018function makecerts {
1119 # https://www.postgresql.org/docs/9.5/static/ssl-tcp.html
@@ -55,14 +63,19 @@ function start {
5563
5664 # -v "$pgroot:/var/lib/postgresql/data" \ # this can be used to inspect logs since we'll have the server data dir available after the sever stops
5765
58- echo " $( tput setaf 4) Waiting for server to be ready$( tput sgr0) "
66+ echo " $( tput setaf 4) Waiting for server to be ready (timeout: ${startup_timeout} s)$( tput sgr0) "
67+ start_time=$( date +%s)
68+
5969 if [ " $1 " = " unix" ]; then
6070 # For unix socket mode, we need to wait past the init restart cycle.
6171 # During init, postgres listens on unix socket with listen_addresses='',
6272 # then shuts down and restarts in production mode.
6373 # Require 3 successful connections with delays to ensure we're past init.
6474 success_count=0
6575 while [ $success_count -lt 3 ]; do
76+ if [ $(( $(date +% s) - start_time)) -ge $startup_timeout ]; then
77+ fail_with_logs " Timed out waiting for PostgreSQL to be ready (unix socket mode)"
78+ fi
6679 if PGHOST=" $socket_dir " PGUSER=postgres PGPASSWORD=pgmoon psql -c ' SELECT 1' > /dev/null 2>&1 ; then
6780 success_count=$(( success_count + 1 ))
6881 else
@@ -71,9 +84,14 @@ function start {
7184 sleep 0.3
7285 done
7386 else
74- until (PGHOST=127.0.0.1 PGPORT=$port PGUSER=postgres PGPASSWORD=pgmoon psql -c ' SELECT pg_reload_conf()' 2> /dev/null); do : ; done
87+ while ! PGHOST=127.0.0.1 PGPORT=$port PGUSER=postgres PGPASSWORD=pgmoon psql -c ' SELECT pg_reload_conf()' > /dev/null 2>&1 ; do
88+ if [ $(( $(date +% s) - start_time)) -ge $startup_timeout ]; then
89+ fail_with_logs " Timed out waiting for PostgreSQL to be ready (TCP mode)"
90+ fi
91+ sleep 0.1
92+ done
7593 fi
76- echo " $( tput setaf 4) Sever is ready$( tput sgr0) "
94+ echo " $( tput setaf 4) Server is ready$( tput sgr0) "
7795}
7896
7997function stop {
0 commit comments