ММФБ Юрий: апгрейд Win10→Win11 25H2 + отчёт клиенту PDF
This commit is contained in:
38
snippets/netbird-watchdog/netbird-watchdog.sh
Normal file
38
snippets/netbird-watchdog/netbird-watchdog.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
# netbird-watchdog.sh — рестарт netbird если daemon застрял
|
||||
# (Management Connected, но Relays=0 или Peers=0 при ненулевом total)
|
||||
# Минимум 5 минут между рестартами чтобы не зацикливалось.
|
||||
|
||||
LOCK=/run/netbird-watchdog.last-restart
|
||||
NOW=$(date +%s)
|
||||
|
||||
if [ -f "$LOCK" ]; then
|
||||
LAST=$(cat "$LOCK")
|
||||
if [ $((NOW - LAST)) -lt 300 ]; then
|
||||
exit 0 # был рестарт менее 5 мин назад
|
||||
fi
|
||||
fi
|
||||
|
||||
STATUS=$(netbird status 2>&1) || exit 0
|
||||
echo "$STATUS" | grep -q "^Management: Connected" || exit 0 # даём демону самому подняться
|
||||
|
||||
stuck=0
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
Relays:*|"Peers count:"*)
|
||||
cur=$(echo "$line" | awk '{print $(NF-1)}' | awk -F/ '{print $1}')
|
||||
total=$(echo "$line" | awk '{print $(NF-1)}' | awk -F/ '{print $2}')
|
||||
[ -z "$cur" ] || [ -z "$total" ] && continue
|
||||
if [ "$total" -gt 0 ] && [ "$cur" -eq 0 ]; then
|
||||
logger -t netbird-watchdog "stuck: $line — will restart"
|
||||
stuck=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done <<< "$STATUS"
|
||||
|
||||
if [ "$stuck" = "1" ]; then
|
||||
echo "$NOW" > "$LOCK"
|
||||
systemctl restart netbird
|
||||
logger -t netbird-watchdog "netbird restarted"
|
||||
fi
|
||||
Reference in New Issue
Block a user