-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.sh
More file actions
executable file
·59 lines (47 loc) · 1.24 KB
/
monitor.sh
File metadata and controls
executable file
·59 lines (47 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# rektSafe Server Monitor Script
# Checks server every 5 minutes and restarts if no response
URL="http://localhost:3000"
CHECK_INTERVAL=300 # 5 minutes in seconds
DIST_DIR="/Users/shachindra/Projects/rektsafe/dist"
LOG_FILE="/tmp/rektsafe_monitor.log"
PID_FILE="/tmp/rektsafe_server.pid"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
check_server() {
curl -s --max-time 10 "$URL/zksig/" > /dev/null 2>&1
return $?
}
start_server() {
log "Starting server..."
# Kill any existing server on port 3000
lsof -ti:3000 | xargs kill -9 2>/dev/null || true
sleep 2
# Start new server
cd "$DIST_DIR" && python3 -m http.server 3000 > /dev/null 2>&1 &
echo $! > "$PID_FILE"
sleep 3
if check_server; then
log "Server started successfully on $URL"
return 0
else
log "ERROR: Failed to start server"
return 1
fi
}
# Main monitoring loop
log "=== Monitor started ==="
# Start server initially if not running
if ! check_server; then
start_server
fi
while true; do
if check_server; then
log "Health check: OK"
else
log "Health check: FAILED - Restarting server..."
start_server
fi
sleep $CHECK_INTERVAL
done