Created
June 27, 2017 14:30
-
-
Save nicerobot/1136dcfba6ce3da67ce3ded5101a4078 to your computer and use it in GitHub Desktop.
A better wait-for-postgres.sh
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 -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
You will need to install the "postgresql-client" package for these commands to be available in the webapp.
The included
pg_isready
command achieves the same as above without the retry limit.See the complete config using this technique here.
A simplified Dockerfile is shown below. You will need to include a
pgsql
link for hostname in docker-compose.yml.For the above script replace the CMD with :