#!/bin/sh
set -e

export PYTHONUNBUFFERED=1

PORT="${PORT:-8080}"

# Ensure dashboard.html points to index.html to avoid code duplication
if [ ! -L dashboard.html ] && [ ! -f dashboard.html ]; then
    ln -sf index.html dashboard.html
fi

echo "Running initial website check..."
python3 monitor.py --once || true

echo "Starting background website monitor..."
python3 monitor.py &

echo "Starting web dashboard on port ${PORT}..."
exec python3 -m http.server "${PORT}"

