Skip to content

Instantly share code, notes, and snippets.

@hyeonjae
Created June 8, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyeonjae/dbcf62ae973a56e1bf271e82275fd0e8 to your computer and use it in GitHub Desktop.
Save hyeonjae/dbcf62ae973a56e1bf271e82275fd0e8 to your computer and use it in GitHub Desktop.
#!/bin/sh
WAIT_HOST=$1
WAIT_PORT=$2
WAIT_LOOP=60
WAIT_DELAY=1
function is_healthy () {
host=$1
port=$2
res=$(nc -z $host $port > /dev/null 2>&1)
suc=$?
if [ $suc != "0" ]
then
return 1
fi
res=$(curl -fsSL "$host:$port/_cat/health?h=status" 2> /dev/null)
if [ "$res" != "green" ]
then
return 2
fi
return 0
}
for i in $(seq 1 $WAIT_LOOP)
do
is_healthy $WAIT_HOST $WAIT_PORT
retval=$?
if [ $retval == "0" ]
then
echo success
break
elif [ $retval == "1" ]
then
echo "port_closed"
elif [ $retval == "2" ]
then
echo "not_green"
else
echo "???"
fi
sleep $WAIT_DELAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment