This commit is contained in:
sharky committed 2026-10-04 15:54:09 +02:00
1 parent dcd95dc19c
commit c9ad685503
1 file changed
+51 -17
+51 -17
View File
@@ -146,7 +146,7 @@ wait_for_apt() {
} }
host_reboot_required() { host_reboot_required() {
if [[ -e /var/run/reboot-required ]]; then if [[ -e /var/run/reboot-required || -e /run/reboot-required ]]; then
return 0 return 0
fi fi
@@ -155,16 +155,22 @@ host_reboot_required() {
running="$(uname -r)" running="$(uname -r)"
# Paketnamen sauber in Kernel-Versionen umwandeln.
# Wichtig: bei "proxmox-kernel-...-signed" muss "-signed" entfernt werden.
# Die alte Regex konnte "-signed" in die Versionsnummer aufnehmen und
# dadurch fälschlich einen Host-Neustart verlangen.
latest="$( latest="$(
dpkg-query -W -f='${Package}\n' \ dpkg-query -W -f='${Package}\n' \
'proxmox-kernel-*-signed' \ 'proxmox-kernel-*-signed' \
'pve-kernel-*' 2>/dev/null | 'pve-kernel-*' 2>/dev/null |
sed -nE 's/^(proxmox-kernel-|pve-kernel-)(.+)(-signed)?$/\2/p' | sed -nE \
-e 's/^proxmox-kernel-(.+)-signed$/\1/p' \
-e 's/^pve-kernel-(.+)$/\1/p' |
sort -V | sort -V |
tail -n1 tail -n1
)" )"
if [[ -n "$latest" && "$running" != *"$latest"* ]]; then if [[ -n "$latest" && "$running" != "$latest" ]]; then
return 0 return 0
fi fi
@@ -454,10 +460,37 @@ vm_exec() {
local id="$1" local id="$1"
shift shift
local cmd="$*" local cmd="$*"
local output
local qm_rc
local guest_rc
# qm guest exec waits for the command and returns its exit status. # "qm guest exec" liefert das Ergebnis als JSON. Für die Entscheidung,
# bash -lc gives us the same shell environment/quoting model as in LXCs. # ob apt/test innerhalb der VM erfolgreich war, werten wir deshalb
qm guest exec "$id" -- bash -lc "$cmd" # ausdrücklich "exitcode" des Gastprozesses aus.
output="$(qm guest exec "$id" -- bash -lc "$cmd" 2>&1)"
qm_rc=$?
printf '%s\n' "$output"
if (( qm_rc != 0 )); then
return "$qm_rc"
fi
guest_rc="$(
printf '%s\n' "$output" |
sed -nE 's/^[[:space:]]*"exitcode"[[:space:]]*:[[:space:]]*([0-9]+),?[[:space:]]*$/\1/p' |
head -n1
)"
if [[ -z "$guest_rc" ]]; then
return 1
fi
if (( guest_rc == 0 )); then
return 0
fi
return 1
} }
check_vm() { check_vm() {
@@ -482,14 +515,16 @@ check_vm() {
fi fi
if ! vm_agent_enabled "$id"; then if ! vm_agent_enabled "$id"; then
log "VM $id ($name): QEMU Guest Agent nicht aktiviert -> übersprungen." log "FEHLER: VM $id ($name): QEMU Guest Agent nicht aktiviert."
VM_SKIPPED=$((VM_SKIPPED + 1)) VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
return return
fi fi
if ! vm_agent_alive "$id"; then if ! vm_agent_alive "$id"; then
log "VM $id ($name): QEMU Guest Agent nicht erreichbar -> übersprungen." log "FEHLER: VM $id ($name): QEMU Guest Agent nicht erreichbar."
VM_SKIPPED=$((VM_SKIPPED + 1)) VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
return return
fi fi
@@ -560,24 +595,26 @@ update_vm() {
fi fi
if ! vm_agent_enabled "$id"; then if ! vm_agent_enabled "$id"; then
log "VM $id ($name): QEMU Guest Agent nicht aktiviert -> übersprungen." log "FEHLER: VM $id ($name): QEMU Guest Agent nicht aktiviert."
if [[ "$started_by_us" == "yes" ]]; then if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id" qm shutdown "$id" --timeout 60 || qm stop "$id"
fi fi
VM_SKIPPED=$((VM_SKIPPED + 1)) VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
return return
fi fi
if ! vm_agent_alive "$id"; then if ! vm_agent_alive "$id"; then
log "VM $id ($name): QEMU Guest Agent nicht erreichbar -> übersprungen." log "FEHLER: VM $id ($name): QEMU Guest Agent nicht erreichbar."
if [[ "$started_by_us" == "yes" ]]; then if [[ "$started_by_us" == "yes" ]]; then
qm shutdown "$id" --timeout 60 || qm stop "$id" qm shutdown "$id" --timeout 60 || qm stop "$id"
fi fi
VM_SKIPPED=$((VM_SKIPPED + 1)) VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
return return
fi fi
@@ -684,9 +721,6 @@ reboot_pending_guests() {
fi fi
done done
# Für Linux-VMs ist die automatische Paketinstallation in dieser Version
# noch nicht freigeschaltet. Die Liste ist bereits vorgesehen, damit die
# gleiche Entscheidungslogik später ohne Umbau verwendet werden kann.
for id in "${VM_REBOOT_PENDING[@]}"; do for id in "${VM_REBOOT_PENDING[@]}"; do
name="$(vm_name "$id")" name="$(vm_name "$id")"
name="${name:-unbekannt}" name="${name:-unbekannt}"