From 593f40ee44d6bb8cf64f6f174fdf6d373cc9ba80 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 18 Feb 2026 14:22:27 -0600 Subject: [PATCH] Add backup monitoring script for auto-restart - Created monitor-restart.sh script for manual or cron-based monitoring - Script checks all 3 sites and auto-restarts if down - Includes proper process cleanup with pkill - Logs to /tmp/web-monitor.log --- monitor-restart.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 monitor-restart.sh diff --git a/monitor-restart.sh b/monitor-restart.sh new file mode 100755 index 0000000..bbac30c --- /dev/null +++ b/monitor-restart.sh @@ -0,0 +1,51 @@ +#!/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 ==="