40 lines
920 B
Bash
Executable File
40 lines
920 B
Bash
Executable File
#!/bin/bash
|
|
# Wait until LIVEKIT_URL (from .env) accepts TCP. Used so publishers do not
|
|
# race the local test livekit-server on boot. When LIVEKIT_URL points at a
|
|
# remote host this waits on that host instead.
|
|
set -u
|
|
ENV_FILE=/home/fdenkena/livekit-cameras/.env
|
|
if [ -f "$ENV_FILE" ]; then
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
. "$ENV_FILE"
|
|
set +a
|
|
fi
|
|
URL="${LIVEKIT_URL:-ws://127.0.0.1:7880}"
|
|
rest="${URL#*://}"
|
|
hostport="${rest%%/*}"
|
|
host="${hostport%%:*}"
|
|
port="${hostport##*:}"
|
|
case "$hostport" in
|
|
*:*) ;;
|
|
*)
|
|
case "$URL" in
|
|
wss://*) port=443 ;;
|
|
*) port=80 ;;
|
|
esac
|
|
;;
|
|
esac
|
|
if [ "$host" = "localhost" ]; then
|
|
host=127.0.0.1
|
|
fi
|
|
echo "wait-for-livekit: $host:$port"
|
|
for _ in $(seq 1 30); do
|
|
if (echo >/dev/tcp/"$host"/"$port") 2>/dev/null; then
|
|
echo "wait-for-livekit: ready"
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "wait-for-livekit: $host:$port not reachable after 30s" >&2
|
|
exit 1
|