Last active
June 24, 2016 20:55
-
-
Save CzechJiri/29c9862393c6a9d4435a2bfd50cf546d to your computer and use it in GitHub Desktop.
running application and DB using docker-compose.yml is tricky, because app will not wait for DB to be fully up and read to accept connections (docker-compose.yml only deals with dependencies). This function can be part of application entrypoint script, it waits up to 30 seconds for postgres to start. It uses pg_isready (works even without passwo…
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
function pg_ready() | |
{ | |
waitTime=30 # keep trying for x seconds | |
n=0 | |
until [ $n -ge $waitTime ]; do | |
# please note pg_isready does not care about username/dbname | |
# you can add correct values if you want to avoid errors in PG log | |
pg_isready --host=$DB_HOST --port=$DB_PORT && break | |
n=$[$n+1] | |
sleep 1; | |
done | |
} | |
if pg_ready ; then | |
echo "INFO: WHIIIIII let start the app." | |
else | |
echo "ERROR: Database $$DB_HOST:$DB_PORT not found." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment