Created
December 18, 2019 08:59
-
-
Save chocobn69/ed5f6cad1cfe39405bd446afaf321440 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
set -eo pipefail | |
host="$(hostname --ip-address || echo '127.0.0.1')" | |
user="${POSTGRES_USER:-postgres}" | |
db="${POSTGRES_DB:-$POSTGRES_USER}" | |
export PGPASSWORD="${POSTGRES_PASSWORD:-}" | |
args=( | |
# force postgres to not use the local unix socket (test "external" connectibility) | |
--host "$host" | |
--username "$user" | |
--dbname "$db" | |
--quiet --no-align --tuples-only --no-psqlrc | |
) | |
if select="$(echo 'SELECT 1;' | psql "${args[@]}"| xargs echo -n )" && [ "$select" = '1' ]; then | |
exit 0 | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment