Created
June 8, 2020 14:44
-
-
Save hyeonjae/dbcf62ae973a56e1bf271e82275fd0e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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