Skip to content

Instantly share code, notes, and snippets.

@tacone
Created October 10, 2019 10:46
Show Gist options
  • Save tacone/7c27175f822f2067ebc5fb80749c8079 to your computer and use it in GitHub Desktop.
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)
#!/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