Try global mirrors first; add apt fallback

Reorder mirror probing in misc/build.func and misc/install.func to scan global (OTHERS) mirrors first and fall back to regional mirrors—pick up to 3 random reachable mirrors and try them. Rename related variables accordingly and keep the fallback logic intact. Update tools/pve/update-lxcs-cron.sh to define region-specific Debian mirror lists, detect container timezone to pick regional vs other mirrors, and implement a fallback loop that checks mirror connectivity, rewrites APT URIs to use a working mirror, and retries apt-get update before proceeding with dist-upgrade. These changes improve resilience against local CDN/local-regional outages by preferring globally reachable mirrors first and providing an automated mirror-switch fallback.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-26 14:52:03 +01:00
parent 9db2169ee0
commit cd1c412822
2 changed files with 34 additions and 34 deletions

View File

@@ -4655,14 +4655,14 @@ EOF'
echo "$result" | xargs echo "$result" | xargs
} }
# Phase 1: Scan regional mirrors, pick 3 random, try them # Phase 1: Scan global mirrors first (independent of local CDN issues)
echo " [scan] Checking regional mirrors..." echo " [scan] Checking global mirrors..."
REGIONAL_OK=$(scan_reachable "$REGIONAL") OTHERS_OK=$(scan_reachable "$OTHERS")
REGIONAL_PICK=$(printf "%s\n" $REGIONAL_OK | shuf | head -3 | xargs) OTHERS_PICK=$(printf "%s\n" $OTHERS_OK | shuf | head -3 | xargs)
R_COUNT=$(echo $REGIONAL_PICK | wc -w) O_COUNT=$(echo $OTHERS_PICK | wc -w)
echo " [scan] $R_COUNT regional mirrors reachable (of $(echo $REGIONAL | wc -w))" echo " [scan] $O_COUNT global mirrors reachable (of $(echo $OTHERS | wc -w))"
for mirror in $REGIONAL_PICK; do for mirror in $OTHERS_PICK; do
echo " [try] $mirror ..." echo " [try] $mirror ..."
try_mirrors "$mirror" && exit 0 try_mirrors "$mirror" && exit 0
done done
@@ -4673,14 +4673,14 @@ EOF'
try_mirrors "ftp.debian.org" && exit 0 try_mirrors "ftp.debian.org" && exit 0
fi fi
# Phase 3: Scan rest-of-world mirrors, pick 3 random, try them # Phase 3: Fall back to regional mirrors
echo " [scan] Checking global mirrors..." echo " [scan] Checking regional mirrors..."
OTHERS_OK=$(scan_reachable "$OTHERS") REGIONAL_OK=$(scan_reachable "$REGIONAL")
OTHERS_PICK=$(printf "%s\n" $OTHERS_OK | shuf | head -3 | xargs) REGIONAL_PICK=$(printf "%s\n" $REGIONAL_OK | shuf | head -3 | xargs)
O_COUNT=$(echo $OTHERS_PICK | wc -w) R_COUNT=$(echo $REGIONAL_PICK | wc -w)
echo " [scan] $O_COUNT global mirrors reachable (of $(echo $OTHERS | wc -w))" echo " [scan] $R_COUNT regional mirrors reachable (of $(echo $REGIONAL | wc -w))"
for mirror in $OTHERS_PICK; do for mirror in $REGIONAL_PICK; do
echo " [try] $mirror ..." echo " [try] $mirror ..."
try_mirrors "$mirror" && exit 0 try_mirrors "$mirror" && exit 0
done done

View File

@@ -265,17 +265,17 @@ pkg_update() {
local apt_ok=false local apt_ok=false
# Phase 1: Scan regional mirrors, pick 3 random, try them # Phase 1: Scan global mirrors first (independent of local CDN issues)
msg_info "Scanning regional mirrors..." msg_info "Scanning global mirrors..."
local regional_ok local others_ok
regional_ok=$(_scan_reachable "$regional") others_ok=$(_scan_reachable "$others")
local regional_pick local others_pick
regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs) others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs)
local r_count local o_count
r_count=$(echo "$regional_pick" | wc -w) o_count=$(echo "$others_pick" | wc -w)
msg_info "Found ${r_count} regional mirrors to try" msg_info "Found ${o_count} global mirrors to try"
for mirror in $regional_pick; do for mirror in $others_pick; do
msg_info "Trying mirror: ${mirror}" msg_info "Trying mirror: ${mirror}"
if _try_apt_mirror "$mirror"; then if _try_apt_mirror "$mirror"; then
apt_ok=true apt_ok=true
@@ -293,18 +293,18 @@ pkg_update() {
fi fi
fi fi
# Phase 3: Scan rest-of-world mirrors, pick 3 random, try them # Phase 3: Fall back to regional mirrors
if [[ "$apt_ok" != true ]]; then if [[ "$apt_ok" != true ]]; then
msg_info "Scanning global mirrors..." msg_info "Scanning regional mirrors..."
local others_ok local regional_ok
others_ok=$(_scan_reachable "$others") regional_ok=$(_scan_reachable "$regional")
local others_pick local regional_pick
others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs) regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs)
local o_count local r_count
o_count=$(echo "$others_pick" | wc -w) r_count=$(echo "$regional_pick" | wc -w)
msg_info "Found ${o_count} global mirrors to try" msg_info "Found ${r_count} regional mirrors to try"
for mirror in $others_pick; do for mirror in $regional_pick; do
msg_info "Trying mirror: ${mirror}" msg_info "Trying mirror: ${mirror}"
if _try_apt_mirror "$mirror"; then if _try_apt_mirror "$mirror"; then
apt_ok=true apt_ok=true