Created
November 12, 2019 22:56
-
-
Save calexandrepcjr/681c2bfa1ca648fcea378059fbd0c733 to your computer and use it in GitHub Desktop.
Script to help pipelines detect postgres database containers ready
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 | |
triesLimit=20 # Tries for 10s | |
isDatabaseReady() { | |
local lastContainerName=$(docker ps -lq) | |
local databaseReadyLogMessage="database system is ready to accept connections" | |
echo $(docker logs $lastContainerName --tail 1 | grep -c "$databaseReadyLogMessage") | |
} | |
waitForDatabase() { | |
local tries=0 | |
until [ $tries -gt $triesLimit -o $(isDatabaseReady) -gt 0 ] | |
do | |
sleep .5s | |
((tries++)) | |
done | |
} | |
waitForDatabase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment