ensure-dashboard-running.sh
1 #!/bin/bash 2 # 3 # Dashboard Health Monitor 4 # Checks if dashboard is running on port 8501 and relaunches if down 5 # Runs with lowest priority (nice 19, ionice idle class) 6 # 7 8 set -euo pipefail 9 10 # Check if port 8501 is in use 11 if ss -tlnp | grep -q ":8501" >/dev/null 2>&1; then 12 echo "Dashboard is running on port 8501" 13 exit 0 14 fi 15 16 echo "Dashboard not detected on port 8501, relaunching..." 17 18 # Change to project directory 19 cd "$(dirname "$0")/.." || exit 1 20 21 # Launch dashboard with lowest priority 22 # nice 19 = lowest CPU priority 23 # ionice -c 3 = idle I/O priority (only when no other I/O) - optional 24 if command -v ionice >/dev/null 2>&1; then 25 nohup nice -n 19 ionice -c 3 npm run dashboard \ 26 >/dev/null 2>&1 & 27 else 28 nohup nice -n 19 npm run dashboard \ 29 >/dev/null 2>&1 & 30 fi 31 32 # Wait a moment and verify it started 33 sleep 3 34 35 if ss -tlnp | grep -q ":8501" >/dev/null 2>&1; then 36 echo "Dashboard successfully relaunched" 37 exit 0 38 else 39 echo "WARNING: Dashboard not available - will retry next cycle (non-critical)" 40 exit 0 41 fi