Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created August 14, 2021 20:37
Show Gist options
  • Save kissgyorgy/978c55c448f9c1cc32a86a7b920cdf28 to your computer and use it in GitHub Desktop.
Save kissgyorgy/978c55c448f9c1cc32a86a7b920cdf28 to your computer and use it in GitHub Desktop.
bash: Wait for socket to became active
#!/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