#!/bin/zsh # Monitor and auto-restart web apps # This script checks if the three main web apps are running and restarts them if needed LOG_FILE="/tmp/web-monitor.log" log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a $LOG_FILE } check_and_restart() { local name=$1 local url=$2 local port=$3 local dir=$4 # Check if responding if curl -s -o /dev/null -w "%{http_code}" $url | grep -q "200"; then log "$name ($port): ✅ OK" return 0 else log "$name ($port): ❌ DOWN - Restarting..." # Kill any process using the port pkill -f "port $port" 2>/dev/null sleep 2 # Restart cd $dir && npm run dev -- --port $port > /dev/null 2>&1 & # Wait and verify sleep 5 if curl -s -o /dev/null -w "%{http_code}" $url | grep -q "200"; then log "$name ($port): ✅ RESTARTED SUCCESSFULLY" return 0 else log "$name ($port): ❌ FAILED TO RESTART" return 1 fi fi } log "=== Starting monitor check ===" # Check all three sites check_and_restart "gantt-board" "http://localhost:3000" "3000" "/Users/mattbruce/Documents/Projects/OpenClaw/Web/gantt-board" check_and_restart "blog-backup" "http://localhost:3003" "3003" "/Users/mattbruce/Documents/Projects/OpenClaw/Web/blog-backup" check_and_restart "heartbeat-monitor" "http://localhost:3005" "3005" "/Users/mattbruce/Documents/Projects/OpenClaw/Web/heartbeat-monitor" log "=== Monitor check complete ==="