#!/bin/bash # WireGuard tunnel monitor — controlla connettività e tenta restart se down. # Schedulato ogni 5 minuti dal crontab di mauro. LOG_FILE="/mnt/ssd/adrian/scripts/logs/wg_monitor.log" VPS_IP="10.0.0.1" INTERFACE="wg0" log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE" } if ping -c 2 -W 3 "$VPS_IP" > /dev/null 2>&1; then exit 0 # tunnel up, nessun log fi log "WARN: tunnel $INTERFACE non raggiunge $VPS_IP — tentativo restart" sudo systemctl restart "wg-quick@$INTERFACE" sleep 5 if ping -c 2 -W 3 "$VPS_IP" > /dev/null 2>&1; then log "OK: tunnel ripristinato dopo restart" else log "ERROR: tunnel ancora down dopo restart — intervento manuale necessario" fi