forked from openmaptiles/openmaptiles-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgwait
executable file
·27 lines (23 loc) · 842 Bytes
/
pgwait
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash
# Wait for Postgres to start using pg_isready
set -o errexit
set -o pipefail
set -o nounset
# For backward compatibility, allow both PG* and POSTGRES_* forms,
# with the non-standard POSTGRES_* form taking precedence.
# An error will be raised if neither form is given, except for the PGPORT
export PGHOST="${POSTGRES_HOST:-${PGHOST?}}"
export PGDATABASE="${POSTGRES_DB:-${PGDATABASE?}}"
export PGUSER="${POSTGRES_USER:-${PGUSER?}}"
export PGPORT="${POSTGRES_PORT:-${PGPORT:-5432}}"
: "${MAX_RETRIES:=40}" # Maximum number of pg_isready calls
tries=0
while ! pg_isready -q
do
tries=$((tries + 1))
if (( tries > MAX_RETRIES )); then
echo "... gave up waiting for Postgres: PGHOST=${PGHOST} PGDATABASE=${PGDATABASE} PGUSER=${PGUSER} PGPORT=${PGPORT} pg_isready"
exit 1
fi
sleep 2
done