|
|
|
@ -278,6 +278,16 @@ when_ports_available(){
|
|
|
|
|
local host="$2"
|
|
|
|
|
local ports="${@:3}"
|
|
|
|
|
local retry_interval=1
|
|
|
|
|
if [ -z "$max_secs" ]; then
|
|
|
|
|
echo 'when_ports_available: max_secs $1 not set'
|
|
|
|
|
exit 1
|
|
|
|
|
elif [ -z "$host" ]; then
|
|
|
|
|
echo 'when_ports_available: host $2 not set'
|
|
|
|
|
exit 1
|
|
|
|
|
elif [ -z "$ports" ]; then
|
|
|
|
|
echo 'when_ports_available: ports $3 not set'
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
local max_tries=$(($max_secs / $retry_interval))
|
|
|
|
|
# Linux nc doens't have -z switch like Mac OSX version
|
|
|
|
|
local nc_cmd="nc -vw $retry_interval $host <<< ''"
|
|
|
|
@ -291,8 +301,8 @@ when_ports_available(){
|
|
|
|
|
echo "cmd: ${cmd// \&\>\/dev\/null}"
|
|
|
|
|
local found=0
|
|
|
|
|
if which nc &>/dev/null; then
|
|
|
|
|
for((i=0; i < $max_tries; i++)); do
|
|
|
|
|
timestamp "trying host '$host' port(s) '$ports'"
|
|
|
|
|
for((i=1; i <= $max_tries; i++)); do
|
|
|
|
|
timestamp "$i trying host '$host' port(s) '$ports'"
|
|
|
|
|
if eval $cmd; then
|
|
|
|
|
found=1
|
|
|
|
|
break
|
|
|
|
@ -310,5 +320,33 @@ when_ports_available(){
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when_url_content(){
|
|
|
|
|
local max_secs="$1"
|
|
|
|
|
local url="$2"
|
|
|
|
|
local expected_regex="$3"
|
|
|
|
|
local retry_interval=1
|
|
|
|
|
if [ -z "$max_secs" ]; then
|
|
|
|
|
echo 'when_url_content: max_secs $1 not set'
|
|
|
|
|
exit 1
|
|
|
|
|
elif [ -z "$url" ]; then
|
|
|
|
|
echo 'when_url_content: url $2 not set'
|
|
|
|
|
exit 1
|
|
|
|
|
elif [ -z "$expected_regex" ]; then
|
|
|
|
|
echo 'when_url_content: expected content $3 not set'
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
local max_tries=$(($max_secs / $retry_interval))
|
|
|
|
|
echo "waiting up to $max_secs secs for HTTP interface to come up with expected regex content"
|
|
|
|
|
for((i=1; i <= $max_tries; i++)); do
|
|
|
|
|
timestamp "$i trying $url"
|
|
|
|
|
if curl -s "$url" | grep -q "$expected_regex"; then
|
|
|
|
|
echo "URL content detected"
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
echo 'URL content still not detected, giving up!'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# restore original srcdir
|
|
|
|
|
srcdir="$srcdir_bash_tools_utils"
|
|
|
|
|