Skip to content

Instantly share code, notes, and snippets.

@7error
Forked from nicerobot/wait-for-postgres.sh
Created April 25, 2020 14:42
Show Gist options
  • Save 7error/79a5bc54603d6b10f598f0056fb5fa13 to your computer and use it in GitHub Desktop.
Save 7error/79a5bc54603d6b10f598f0056fb5fa13 to your computer and use it in GitHub Desktop.
A better wait-for-postgres.sh
#!/bin/bash -e
# wait-for-postgres.sh
# Adapted from https://docs.docker.com/compose/startup-order/
# Expects the necessary PG* variables.
until psql -c '\l'; do
echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is unavailable - sleeping"
sleep 1
done
echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is up - executing command"
exec ${@}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment