33 lines
580 B
Bash
Executable File
33 lines
580 B
Bash
Executable File
#!/bin/sh
|
|
|
|
: ${SLEEP_LENGTH:=2}
|
|
: ${TIMEOUT_LENGTH:=60}
|
|
|
|
DIR="$(cd $(dirname $0) && pwd)"
|
|
BIN_DIR="$(cd $DIR/.. && pwd)"
|
|
|
|
# Import functions
|
|
. $BIN_DIR/helper/fn
|
|
|
|
wait_for() {
|
|
START="$(date +%s)"
|
|
echo "Waiting for $1 to listen on $2..."
|
|
while ! nc -z $1 $2; do
|
|
if [ $(($(date +%s) - $START)) -gt $TIMEOUT_LENGTH ]; then
|
|
abort "Service $1:$2 did not start within $TIMEOUT_LENGTH seconds. Aborting..."
|
|
fi
|
|
echo "sleeping"
|
|
sleep $SLEEP_LENGTH
|
|
done
|
|
}
|
|
|
|
for var in "$@"
|
|
do
|
|
host=${var%:*}
|
|
port=${var#*:}
|
|
wait_for $host $port
|
|
ok "Listening ${host}:${port}"
|
|
done
|
|
|
|
exit 0
|