Created
June 1, 2020 10:21
-
-
Save byF/ac877f903e8f54ad2623c6a13fd1cb5e to your computer and use it in GitHub Desktop.
wait-for-pg script which can be used as Docker entrypoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
if [ -z ${DATABASE_HOST+x} ] | |
then | |
echo "$0: Provide DATABASE_HOST environment variable" >&2 | |
exit 1 | |
fi | |
attempt=1 | |
until PGPASSWORD="${DATABASE_PASS}" \ | |
pg_isready \ | |
-h "${DATABASE_HOST}" \ | |
-p "${DATABASE_PORT:="5432"}" \ | |
-U "${DATABASE_USER:="postgres"}"; do | |
attempts=$((attempts+1)) | |
if [ $attempts -eq ${RECONNECT_ATTEMPTS:=3} ] | |
then | |
echo "$0: Failed to reach the database at ${DATABASE_HOST}" >&2 | |
exit 1 | |
fi | |
sleep 5 | |
done | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment