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
This commit is contained in:
parent
08bfe94fdd
commit
593f40ee44
51
monitor-restart.sh
Executable file
51
monitor-restart.sh
Executable file
@ -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 ==="
|
||||
Loading…
Reference in New Issue
Block a user