Last active
May 25, 2023 09:15
-
-
Save jimeh/03019b4d7d0bbfccaa06997940c2d2b3 to your computer and use it in GitHub Desktop.
Revisions
-
jimeh revised this gist
Aug 16, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ check_http() { wget -T 1 -S -q -O - "$1" 2>&1 | head -1 | grep -E 'HTTP.+\s2[0-9]{2}' > /dev/null 2>&1 return $? } @@ -67,4 +67,4 @@ if [ -n "$WAIT_FOR_TARGETS" ]; then done fi exec "$@" -
jimeh revised this gist
Aug 16, 2021 . 1 changed file with 16 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,8 @@ [ -n "$DEBUG" ] && set -x check_http() { wget -T 1 -S -q -O - "$1" 2>&1 | head -1 | head -1 | grep -E 'HTTP.+\s2\d{2}' > /dev/null 2>&1 return $? } @@ -15,7 +15,7 @@ check_tcp() { exit 2 fi nc -z -w1 "$host" "$port" > /dev/null 2>&1 return $? } @@ -24,14 +24,24 @@ wait_for() { uri="$2" timeout="${3:-30}" if [ "$type" = "tcp" ] && [ -z "$(which nc)" ]; then echo "ERROR: nc command not available" >&2 exit 3 fi if [ "$type" = "http" ] && [ -z "$(which wget)" ]; then echo "ERROR: wget command not available" >&2 exit 3 fi seconds=0 while [ "$seconds" -lt "$timeout" ] && ! "check_${type}" "$uri"; do if [ "$seconds" -lt "1" ]; then printf "Waiting for %s ." "$uri" else printf . fi seconds=$((seconds + 1)) sleep 1 done @@ -48,14 +58,13 @@ wait_for() { if [ -n "$WAIT_FOR_TARGETS" ]; then uris="$(echo "$WAIT_FOR_TARGETS" | sed -e 's/\s+/\n/g' | uniq)" for uri in $uris; do if echo "$uri" | grep -E '^https?://.*' > /dev/null 2>&1; then wait_for "http" "$uri" "$WAIT_FOR_TIMEOUT" else wait_for "tcp" "$uri" "$WAIT_FOR_TIMEOUT" fi done fi exec "$@" -
jimeh created this gist
Mar 13, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ #!/bin/sh [ -n "$DEBUG" ] && set -x check_http() { wget -T 1 -S -q -O - "$1" 2>&1 | head -1 | \ head -1 | grep -E 'HTTP.+\s2\d{2}' >/dev/null 2>&1 return $? } check_tcp() { host="$(echo "$1" | cut -d: -f1)" port="$(echo "$1" | cut -d: -f2)" if [ -z "${host}" ] || [ -z "${port}" ]; then echo "TCP target ${1} is not in \"<host>:<port>\" format" >&2 exit 2 fi nc -z -w1 "$host" "$port" >/dev/null 2>&1 return $? } wait_for() { type="$1" uri="$2" timeout="${3:-30}" seconds=0 while [ "$seconds" -lt "$timeout" ] && ! "check_${type}" "$uri"; do if [ "$seconds" -lt "1" ]; then printf "Waiting for %s ." "$uri" else printf . fi seconds=$((seconds+1)) sleep 1 done if [ "$seconds" -lt "$timeout" ]; then if [ "$seconds" -gt "0" ]; then echo " up!" fi else echo " FAIL" echo "ERROR: unable to connect to: $uri" >&2 exit 1 fi } if [ -n "$WAIT_FOR_TARGETS" ]; then uris="$(echo "$WAIT_FOR_TARGETS" | sed -e 's/\s+/\n/g' | uniq)" for uri in $uris; do if echo "$uri" | grep -E '^https?://.*' >/dev/null 2>&1; then wait_for "http" "$uri" "$WAIT_FOR_TIMEOUT" else wait_for "tcp" "$uri" "$WAIT_FOR_TIMEOUT" fi done fi exec "$@"