#!/bin/bash

set -x
host="${1%:*}"
port="${1#*:}"
shift
# shellcheck disable=SC2124
cmd="$@"
until nc -z "$host" "$port"; do
  >&2 echo "Waiting for $host:$port to be available..."
  sleep 1
done
>&2 echo "$host:$port is available!"
exec "$cmd"