Last active
September 28, 2020 14:12
-
-
Save kerasai/7f7dbd4294b227c52def8bf9c2f084d6 to your computer and use it in GitHub Desktop.
Waits until services report as healthy, all services must have a health check defined.
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 | |
set -e | |
# Grab args, shift first off as the timeout. | |
END=$((SECONDS+$1)) | |
shift | |
SERVICES=( $@ ) | |
# Wait for the services to report as healthy. | |
while [ $SECONDS -lt $END ]; do | |
READY=1 | |
# Loop through services, check their health. | |
for SERVICE in "${SERVICES[@]}" | |
do | |
STATUS=`docker inspect --format='{{.State.Health.Status}}' $SERVICE` || true | |
if [ "$STATUS" != "healthy" ]; then | |
echo "Service ${SERVICE} not ready..." | |
READY=0 | |
fi | |
done | |
# None reporting anything other than "healthy". | |
if [ "$READY" -eq 1 ]; then | |
echo "Services ready." | |
exit 0 | |
fi | |
sleep 1 | |
done | |
echo "Services not ready within limit." | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment