Created
October 10, 2019 10:46
-
-
Save tacone/7c27175f822f2067ebc5fb80749c8079 to your computer and use it in GitHub Desktop.
Wait for a port to be open (i.e. for the db to be ready)
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
#!/bin/bash | |
set -e | |
echo "Waiting for port opening on ${1}:${2}..." | |
function check_port() { | |
local host=${1} && shift | |
local port=${1} && shift | |
local retries=90 | |
local wait=1 | |
until( $(nc -zv ${host} ${port}) ); do | |
((retries--)) | |
if [ $retries -lt 0 ]; then | |
echo "Service ${host} didn't become ready in time." | |
exit 1 | |
fi | |
sleep "${wait}" | |
done | |
} | |
check_port ${1} ${2} | |
echo "PORT ${2} is open" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment