Auto-sync: 20260105-122831
This commit is contained in:
41
data/scripts/internet-watchdog.sh
Normal file
41
data/scripts/internet-watchdog.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# Internet Watchdog - Reboots if internet is unreachable for 5 minutes
|
||||
LOG_FILE="/var/log/internet-watchdog.log"
|
||||
FAIL_COUNT=0
|
||||
MAX_FAILS=5
|
||||
CHECK_INTERVAL=60
|
||||
|
||||
log() {
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
check_internet() {
|
||||
for endpoint in 1.1.1.1 8.8.8.8 208.67.222.222; do
|
||||
if ping -c 1 -W 5 "$endpoint" > /dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
log "Watchdog started"
|
||||
|
||||
while true; do
|
||||
if check_internet; then
|
||||
if [ $FAIL_COUNT -gt 0 ]; then
|
||||
log "Internet restored after $FAIL_COUNT failures"
|
||||
fi
|
||||
FAIL_COUNT=0
|
||||
else
|
||||
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||
log "Internet check failed ($FAIL_COUNT/$MAX_FAILS)"
|
||||
|
||||
if [ $FAIL_COUNT -ge $MAX_FAILS ]; then
|
||||
log "CRITICAL: $MAX_FAILS consecutive failures - REBOOTING"
|
||||
sync
|
||||
sleep 2
|
||||
reboot
|
||||
fi
|
||||
fi
|
||||
sleep $CHECK_INTERVAL
|
||||
done
|
||||
Reference in New Issue
Block a user