This commit is contained in:
sharky committed 2026-10-04 15:04:09 +02:00
1 parent 5c361d3c9c
commit 99035841c2
1 file changed
+153 -3
+153 -3
View File
@@ -450,6 +450,16 @@ vm_is_linux() {
esac esac
} }
vm_exec() {
local id="$1"
shift
local cmd="$*"
# qm guest exec waits for the command and returns its exit status.
# bash -lc gives us the same shell environment/quoting model as in LXCs.
qm guest exec "$id" -- bash -lc "$cmd"
}
check_vm() { check_vm() {
local id="$1" local id="$1"
local name local name
@@ -490,15 +500,155 @@ check_vm() {
fi fi
log "VM $id ($name): Debian/Ubuntu erkannt." log "VM $id ($name): Debian/Ubuntu erkannt."
log "VM $id ($name): automatische Paketinstallation über QEMU Guest Agent" log "VM $id ($name): QEMU Guest Agent erreichbar; automatische Updates unterstützt."
log "ist in dieser Version absichtlich noch nicht freigeschaltet."
VM_SKIPPED=$((VM_SKIPPED + 1)) VM_SKIPPED=$((VM_SKIPPED + 1))
} }
update_vm() { update_vm() {
local id="$1" local id="$1"
check_vm "$id" local name
local status
local started_by_us="no"
local reboot_required="no"
name="$(vm_name "$id")"
name="${name:-unbekannt}"
status="$(qm status "$id" 2>/dev/null | awk '{print $2}')"
if is_excluded "$id"; then
log "VM $id ($name): ausgeschlossen."
VM_SKIPPED=$((VM_SKIPPED + 1))
return
fi
if [[ "$status" != "running" ]]; then
if [[ "$UPDATE_STOPPED" != "yes" ]]; then
log "VM $id ($name): gestoppt -> übersprungen."
VM_SKIPPED=$((VM_SKIPPED + 1))
return
fi
log "VM $id ($name): wird für Update gestartet ..."
if ! qm start "$id"; then
log "VM $id ($name): Start fehlgeschlagen."
VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
return
fi
started_by_us="yes"
# Auf den QEMU Guest Agent warten.
local waited=0
while ! vm_agent_alive "$id"; do
if (( waited >= 120 )); then
log "VM $id ($name): QEMU Guest Agent nach 120 Sekunden nicht erreichbar."
if ! qm shutdown "$id" --timeout 60; then
qm stop "$id" || true
fi
VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
return
fi
sleep 5
waited=$((waited + 5))
done
fi
if ! vm_agent_enabled "$id"; then
log "VM $id ($name): QEMU Guest Agent nicht aktiviert -> übersprungen."
if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id"
fi
VM_SKIPPED=$((VM_SKIPPED + 1))
return
fi
if ! vm_agent_alive "$id"; then
log "VM $id ($name): QEMU Guest Agent nicht erreichbar -> übersprungen."
if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id"
fi
VM_SKIPPED=$((VM_SKIPPED + 1))
return
fi
if ! vm_is_linux "$id"; then
log "VM $id ($name): keine unterstützte Debian/Ubuntu-VM -> übersprungen."
if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id"
fi
VM_SKIPPED=$((VM_SKIPPED + 1))
return
fi
log "------------------------------------------------------------"
log "VM $id ($name) aktualisieren"
log "------------------------------------------------------------"
if ! vm_exec "$id" 'apt-get update'; then
log "VM $id ($name): apt-get update FEHLER."
VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id"
fi
return
fi
if ! vm_exec "$id" \
'DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" full-upgrade'
then
log "VM $id ($name): full-upgrade FEHLER."
VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id"
fi
return
fi
if vm_exec "$id" 'test -e /var/run/reboot-required' >/dev/null 2>&1; then
reboot_required="yes"
log "VM $id ($name): Update erfolgreich - Neustart erforderlich."
else
log "VM $id ($name): Update erfolgreich."
fi
VM_OK=$((VM_OK + 1))
if [[ "$started_by_us" == "yes" ]]; then
log "VM $id ($name): war vorher gestoppt -> wird wieder heruntergefahren."
if ! qm shutdown "$id" --timeout 60; then
log "VM $id ($name): sauberer Shutdown fehlgeschlagen -> Stop."
if ! qm stop "$id"; then
log "FEHLER: VM $id ($name) konnte nicht gestoppt werden."
VM_OK=$((VM_OK - 1))
VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
fi
fi
return
fi
if [[ "$reboot_required" == "yes" ]]; then
VM_REBOOT_PENDING+=("$id")
log "VM $id ($name): Neustart vorgemerkt."
fi
} }
reboot_pending_guests() { reboot_pending_guests() {