Created
March 4, 2019 13:52
-
-
Save ZipFile/dc89c5e91b2caf3b1e28b6b5a59dceac to your computer and use it in GitHub Desktop.
Wait for postgres
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
#!/bin/bash | |
if [ -z "$DATABASE_URL" ]; then | |
echo "Missing database url" | |
exit 2 | |
fi | |
RETRIES="${RETRIES:-10}" | |
echo -n "Waiting for postgres..." | |
if ! which psql > /dev/null; then | |
echo 'PSQL_MISSING' | |
exit 3 | |
fi | |
until psql "$DATABASE_URL" -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do | |
echo -n " $((RETRIES--))" | |
sleep 1 | |
done | |
if [ $RETRIES -le 0 ]; then | |
echo " TIME_OUT" | |
exit 1 | |
else | |
echo " OK" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment