summaryrefslogtreecommitdiffstats
path: root/deliveries/wait-for.sh
diff options
context:
space:
mode:
authorChristopher Lott (cl778h) <clott@research.att.com>2017-08-23 18:27:19 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-08-23 21:12:56 -0400
commit978dbcf0a196acbafad72fe1e2478ec0e384f02f (patch)
tree17e1ceaa4a12a599320cbb317947e990bf1a5383 /deliveries/wait-for.sh
parentbc7350dce5b7b1dcd1c472a3922b42c4ea99809d (diff)
Deliver centralized role management feature
Repair multiple defects also. Revise deployment to use docker-compose. Remove all zip archives. Issue: PORTAL-21, PORTAL-25, PORTAL-28, PORTAL-52, PORTAL-69, PORTAL-74, PORTAL-76, PORTAL-80, PORTAL-82 Change-Id: Ie72fec7d35ba78beb162bba6ed27b2caee340c61 Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'deliveries/wait-for.sh')
-rwxr-xr-xdeliveries/wait-for.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/deliveries/wait-for.sh b/deliveries/wait-for.sh
new file mode 100755
index 00000000..be9a443f
--- /dev/null
+++ b/deliveries/wait-for.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+# https://github.com/Eficode/wait-for.git
+# MIT License
+
+TIMEOUT=15
+QUIET=0
+
+echoerr() {
+ if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
+}
+
+usage() {
+ exitcode="$1"
+ cat << USAGE >&2
+Usage:
+ $cmdname host:port [-t timeout] [-- command args]
+ -q | --quiet Do not output any status messages
+ -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
+ -- COMMAND ARGS Execute command with args after the test finishes
+USAGE
+ exit "$exitcode"
+}
+
+wait_for() {
+ command="$*"
+ for i in `seq $TIMEOUT` ; do
+ nc -z "$HOST" "$PORT" > /dev/null 2>&1
+ result=$?
+ if [ $result -eq 0 ] ; then
+ if [ "$QUIET" -ne 1 ]; then echo "Operation succeeded on try $i"; fi
+ if [ -n "$command" ] ; then
+ exec $command
+ fi
+ exit 0
+ fi
+ sleep 1
+ done
+ echo "Operation timed out" >&2
+ exit 1
+}
+
+while [ $# -gt 0 ]
+do
+ case "$1" in
+ *:* )
+ HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
+ PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
+ shift 1
+ ;;
+ -q | --quiet)
+ QUIET=1
+ shift 1
+ ;;
+ -t)
+ TIMEOUT="$2"
+ if [ "$TIMEOUT" = "" ]; then break; fi
+ shift 2
+ ;;
+ --timeout=*)
+ TIMEOUT="${1#*=}"
+ shift 1
+ ;;
+ --)
+ shift
+ break
+ ;;
+ --help)
+ usage 0
+ ;;
+ *)
+ echoerr "Unknown argument: $1"
+ usage 1
+ ;;
+ esac
+done
+
+if [ "$HOST" = "" -o "$PORT" = "" ]; then
+ echoerr "Error: you need to provide a host and port to test."
+ usage 2
+fi
+
+wait_for "$@"