Created
March 1, 2023 22:33
-
-
Save zzak/5e0a9a177145db4f0969f0136318681d to your computer and use it in GitHub Desktop.
Script to wait for localhost service in bash, with retries
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
#!/usr/bin/env bash | |
set -euo pipefail | |
TRIES=0 | |
until [ $TRIES -eq 10 ] || nc -z localhost 3000; do | |
sleep 0.1 | |
TRIES=$(( TRIES+1 )) | |
done | |
if [[ $TRIES -gt 9 ]] | |
then | |
echo "Failed to connect to container..." | |
exit 999 | |
else | |
echo "Container started!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment