#!/bin/bash
set -e

WORK="/home/o11"
cd "$WORK"

echo "[app] Waiting for license server to be ready..."
sleep 5

echo "[app] Starting o11v4 watchdog..."
while true; do
    if ! pgrep -x "o11v4" > /dev/null 2>&1; then
        echo "[app] Starting o11v4 on port 8484..."
        "$WORK/o11v4" \
            -p 8484 \
            -noramfs \
            -f /usr/bin/ffmpeg \
            -path "$WORK/" \
            -noautostart \
            -plstreamname "%s [%p]" &
        sleep 10
    fi
    sleep 20
done
