From 5b6bbd1ed02df9b93bda75d7bfdadfbc911e53b7 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:41:26 +0200 Subject: [PATCH] Improve LXC network wait and gateway check logic Refactors the LXC container network initialization to simplify IP wait logic, reduce gateway ping attempts from 20 to 10, and provide clearer status messages. Now warns instead of failing if the gateway is unreachable but the container has an IP, improving robustness in network checks. --- misc/build.func | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/misc/build.func b/misc/build.func index 99b2d56e..4d6c1b89 100644 --- a/misc/build.func +++ b/misc/build.func @@ -2377,12 +2377,10 @@ EOF if [ "$var_os" != "alpine" ]; then msg_info "Waiting for network in LXC container" - # --- Step 1: Wait until the CT has an IP --- + # --- Step 1: Wait for IP --- for i in {1..20}; do ip_in_lxc=$(pct exec "$CTID" -- ip -4 addr show dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1) - if [ -n "$ip_in_lxc" ]; then - break - fi + [ -n "$ip_in_lxc" ] && break sleep 1 done @@ -2391,20 +2389,23 @@ EOF exit 1 fi - # --- Step 2: Wait until gateway responds --- - for i in {1..20}; do + # --- Step 2: Try to reach gateway --- + gw_ok=0 + for i in {1..10}; do if pct exec "$CTID" -- ping -c1 -W1 "$GATEWAY" >/dev/null 2>&1; then + gw_ok=1 break fi sleep 1 done - if [ "$i" -eq 20 ]; then - msg_error "Gateway $GATEWAY unreachable from CT $CTID (IP $ip_in_lxc)" - exit 1 + if [ "$gw_ok" -eq 1 ]; then + msg_ok "CT $CTID gateway $GATEWAY reachable (IP $ip_in_lxc)" + else + msg_warn "CT $CTID has IP $ip_in_lxc but gateway $GATEWAY did not reply" fi - # --- Step 3: DNS check --- + # --- Step 3: DNS / Internet check --- if pct exec "$CTID" -- getent hosts deb.debian.org >/dev/null 2>&1; then msg_ok "Network in LXC is reachable (DNS OK, IP $ip_in_lxc)" else