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

View File

@@ -265,17 +265,17 @@ pkg_update() {
local apt_ok=false
# Phase 1: Scan regional mirrors, pick 3 random, try them
msg_info "Scanning regional mirrors..."
local regional_ok
regional_ok=$(_scan_reachable "$regional")
local regional_pick
regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs)
local r_count
r_count=$(echo "$regional_pick" | wc -w)
msg_info "Found ${r_count} regional mirrors to try"
# Phase 1: Scan global mirrors first (independent of local CDN issues)
msg_info "Scanning global mirrors..."
local others_ok
others_ok=$(_scan_reachable "$others")
local others_pick
others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs)
local o_count
o_count=$(echo "$others_pick" | wc -w)
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}"
if _try_apt_mirror "$mirror"; then
apt_ok=true
@@ -293,18 +293,18 @@ pkg_update() {
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
msg_info "Scanning global mirrors..."
local others_ok
others_ok=$(_scan_reachable "$others")
local others_pick
others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs)
local o_count
o_count=$(echo "$others_pick" | wc -w)
msg_info "Found ${o_count} global mirrors to try"
msg_info "Scanning regional mirrors..."
local regional_ok
regional_ok=$(_scan_reachable "$regional")
local regional_pick
regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs)
local r_count
r_count=$(echo "$regional_pick" | wc -w)
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}"
if _try_apt_mirror "$mirror"; then
apt_ok=true