#!/usr/bin/env bash # run_bot.sh — starts bot.py and auto-restarts it on crash set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" VENV="$DIR/venv/bin/activate" LOG="$DIR/bot.log" RETRY_DELAY=5 # seconds to wait before restarting after a crash echo "[run_bot] Starting watchdog. Logs → $LOG" | tee -a "$LOG" while true; do echo "[run_bot] $(date -u '+%Y-%m-%d %H:%M:%S UTC') — launching bot.py" | tee -a "$LOG" source "$VENV" python -u "$DIR/bot.py" >> "$LOG" 2>&1 || true EXIT=$? echo "[run_bot] $(date -u '+%Y-%m-%d %H:%M:%S UTC') — bot.py exited (code $EXIT), restarting in ${RETRY_DELAY}s..." | tee -a "$LOG" sleep "$RETRY_DELAY" done