mirror of
https://github.com/thegeeklab/wait-for.git
synced 2024-11-15 01:00:43 +00:00
chore: adjust script formatting
This commit is contained in:
parent
d86854cde4
commit
2aff7ba92c
33
wait-for
33
wait-for
@ -9,10 +9,10 @@ echoerr() {
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
exitcode="$1"
|
exitcode="$1"
|
||||||
cat << USAGE >&2
|
cat <<USAGE >&2
|
||||||
usage: wait-for host:port [-t timeout] [-- command args]
|
usage: wait-for host:port [-t timeout] [-- command args]
|
||||||
|
|
||||||
Synchronize services like docker containers and wait for readiness.
|
Synchronize services like containers and wait for readiness.
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-q | --quiet Do not output any status messages
|
-q | --quiet Do not output any status messages
|
||||||
@ -23,12 +23,12 @@ USAGE
|
|||||||
}
|
}
|
||||||
|
|
||||||
wait_for() {
|
wait_for() {
|
||||||
for _ in $(seq "$WAITFOR_TIMEOUT") ; do
|
for _ in $(seq "$WAITFOR_TIMEOUT"); do
|
||||||
nc -w 1 -z "$WAITFOR_HOST" "$WAITFOR_PORT" > /dev/null 2>&1
|
nc -w 1 -z "$WAITFOR_HOST" "$WAITFOR_PORT" >/dev/null 2>&1
|
||||||
|
|
||||||
result=$?
|
result=$?
|
||||||
if [ $result -eq 0 ] ; then
|
if [ $result -eq 0 ]; then
|
||||||
if [ $# -gt 0 ] ; then
|
if [ $# -gt 0 ]; then
|
||||||
exec "$@"
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
@ -39,35 +39,34 @@ wait_for() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
while [ $# -gt 0 ]
|
while [ $# -gt 0 ]; do
|
||||||
do
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
*:* )
|
*:*)
|
||||||
WAITFOR_HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
|
WAITFOR_HOST=$(printf "%s\n" "$1" | cut -d : -f 1)
|
||||||
WAITFOR_PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
|
WAITFOR_PORT=$(printf "%s\n" "$1" | cut -d : -f 2)
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-q | --quiet)
|
-q | --quiet)
|
||||||
WAITFOR_QUIET=1
|
WAITFOR_QUIET=1
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-t)
|
-t)
|
||||||
WAITFOR_TIMEOUT="$2"
|
WAITFOR_TIMEOUT="$2"
|
||||||
if [ "$WAITFOR_TIMEOUT" = "" ]; then break; fi
|
if [ "$WAITFOR_TIMEOUT" = "" ]; then break; fi
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--timeout=*)
|
--timeout=*)
|
||||||
WAITFOR_TIMEOUT="${1#*=}"
|
WAITFOR_TIMEOUT="${1#*=}"
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
--help)
|
--help)
|
||||||
usage 0
|
usage 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echoerr "unknown argument: $1"
|
echoerr "unknown argument: $1"
|
||||||
usage 1
|
usage 1
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user