Files
croak-bash-utils/wait-for/wait-for-multiply.sh
2026-03-27 16:51:12 +06:00

49 lines
661 B
Bash

#!/bin/sh
# wait-for-multiple.sh (POSIX / sh version)
set -e
HOSTS=""
CMD=""
while [ $# -gt 0 ]; do
case "$1" in
--)
shift
CMD="$*"
break
;;
*)
HOSTS="$HOSTS $1"
shift
;;
esac
done
if [ -z "$HOSTS" ]; then
echo "Usage: $0 host1:port1 host2:port2 ... -- command args"
exit 1
fi
wait_host() {
hostport="$1"
/usr/bin/wait-for-it.sh "$hostport" --timeout=30 --strict
}
PIDS=""
for h in $HOSTS; do
wait_host "$h" &
PIDS="$PIDS $!"
done
FAIL=0
for pid in $PIDS; do
wait $pid || FAIL=1
done
if [ $FAIL -ne 0 ]; then
echo "One or more hosts failed to become available"
exit 1
fi
exec $CMD