Skip to content

Instantly share code, notes, and snippets.

@ZipFile
Created March 4, 2019 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZipFile/dc89c5e91b2caf3b1e28b6b5a59dceac to your computer and use it in GitHub Desktop.
Save ZipFile/dc89c5e91b2caf3b1e28b6b5a59dceac to your computer and use it in GitHub Desktop.
Wait for postgres
#!/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