#!/bin/bash
# Watchdog: restart bot if it's not running
PIDFILE="/tmp/vidbot.pid"
LOGFILE="/tmp/bot.log"

if [ -f "$PIDFILE" ]; then
    PID=$(cat "$PIDFILE")
    if kill -0 "$PID" 2>/dev/null; then
        exit 0  # bot is alive
    fi
fi

# Bot is not running — start it
cd /workspace
nohup python bot.py >> "$LOGFILE" 2>&1 &
echo $! > "$PIDFILE"
echo "$(date) — Bot restarted (PID $!)" >> "$LOGFILE"
