From 0914a4db7db8253eabc1aaf60b17bc2e41e59cfb Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Wed, 25 Nov 2026 12:44:52 +0100 Subject: [PATCH] Monitor-All: ping the container's net0 address lxc-info lists every IPv4 inside the container, Docker bridges and VPN tunnels included, and they often come before the LAN address, so a healthy container was pinged on 172.17.0.1 and restarted. The address now comes from net0's static ip=, else from net0's interface read in the container's network namespace from the host, and only then from lxc-info. A container is restarted after two rounds of three lost pings instead of one. Fixes #18928 --- tools/pve/monitor-all.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/pve/monitor-all.sh b/tools/pve/monitor-all.sh index d1084aea4..f5e9554f0 100644 --- a/tools/pve/monitor-all.sh +++ b/tools/pve/monitor-all.sh @@ -111,9 +111,18 @@ while true; do continue fi # Read the IP from the host side; pct exec depends on tools inside the - # guest, which minimal/OCI images may lack. - IP=$(lxc-info -n "$instance" -iH 2>/dev/null | awk '/^[0-9.]+$/ && !/^(127|169\.254)\./ {print; exit}') - if [ -z "$IP" ] || ! ping -c 1 -W 2 "$IP" >/dev/null 2>&1; then + # guest, which minimal/OCI images may lack. net0's address comes first: + # lxc-info lists Docker bridges and VPN tunnels too, often before it. + net0=$(value_of net0) + IP=$(grep -oP '(^|,)ip=\K[0-9.]+(?=/)' <<<"$net0" || true) + if [ -z "$IP" ]; then + iface=$(grep -oP '(^|,)name=\K[^,]+' <<<"$net0" || true) + pid=$(lxc-info -n "$instance" -pH 2>/dev/null) + [ -n "$pid" ] && IP=$(nsenter -t "$pid" -n ip -4 -o addr show dev "${iface:-eth0}" scope global 2>/dev/null | awk '{sub(/\/.*/, "", $4); print $4; exit}') + fi + [ -z "$IP" ] && IP=$(lxc-info -n "$instance" -iH 2>/dev/null | awk '/^[0-9.]+$/ && !/^(127|169\.254)\./ {print; exit}') + # Two rounds of three pings, so one lost packet does not restart it. + if [ -z "$IP" ] || ! { ping -c 3 -W 2 "$IP" >/dev/null 2>&1 || { sleep 5 && ping -c 3 -W 2 "$IP" >/dev/null 2>&1; }; }; then echo "$(date): CT $instance is not responding, restarting..." pct stop "$instance" >/dev/null 2>&1 sleep 5