-
-
Save kalekseev/5c09c449fedd27ba6c76bee43edf1a0e to your computer and use it in GitHub Desktop.
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
# Small function that checks if a TCP port on localhost is open. | |
# | |
# Timeout after 10 attempts. | |
# | |
# Usage: wait_port <port> | |
wait_port() ( | |
local i=0 port=$1 | |
echo "waiting on port $port" | |
# Bash has a magic filesystem that can be used to do basic TCP. | |
# | |
# Use 127.0.0.1 instead of "localhost" to avoid resolution issues I observed | |
# inside of the container. | |
while ! exec 3<>"/dev/tcp/127.0.0.1/$port"; do | |
sleep 0.1 | |
((i += 1)) | |
if [[ $i == 10 ]]; then | |
echo "error: timeout" | |
return 1 | |
fi | |
done | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment