Created
August 14, 2021 20:37
-
-
Save kissgyorgy/978c55c448f9c1cc32a86a7b920cdf28 to your computer and use it in GitHub Desktop.
bash: Wait for socket to became active
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 | |
# Wait for a socket on given host and port to became active. | |
# Will exit with statuscode 0 if succeeded, -1 otherwise. | |
# Originally got it from the blog post: https://developer.atlassian.com/blog/2015/03/docker-systemd-socket-activation/ | |
host=$1 | |
port=$2 | |
tries=600 | |
for ((i=0; i<$tries; i++)); do | |
if nc -z $host $port > /dev/null ; then | |
exit 0 | |
fi | |
sleep 0.1 | |
done | |
exit -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment