feat: Improve shutdown logic (#1816)

This commit is contained in:
Kroese
2026-07-07 02:32:00 +02:00
committed by GitHub
parent b4754f5826
commit 068b3cb966
+17 -3
View File
@@ -10,6 +10,7 @@ QEMU_PTY="$QEMU_DIR/qemu.pty"
QEMU_END="$QEMU_DIR/qemu.end" QEMU_END="$QEMU_DIR/qemu.end"
_trap() { _trap() {
local func="$1"; shift local func="$1"; shift
local sig local sig
TRAP_PID=$BASHPID TRAP_PID=$BASHPID
@@ -26,6 +27,7 @@ app() {
} }
signalCode() { signalCode() {
local sig="$1" local sig="$1"
case "$sig" in case "$sig" in
@@ -41,6 +43,7 @@ signalCode() {
} }
displayReason() { displayReason() {
local reason="$1" local reason="$1"
case "$reason" in case "$reason" in
@@ -56,6 +59,7 @@ displayReason() {
} }
readQemuPid() { readQemuPid() {
local file="$1" local file="$1"
local __var="$2" local __var="$2"
local pid="" local pid=""
@@ -69,6 +73,7 @@ readQemuPid() {
} }
bootFailed() { bootFailed() {
local fail="" local fail=""
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
@@ -99,6 +104,7 @@ boot() {
} }
legacyBootReady() { legacyBootReady() {
local last local last
local bios="Booting from Hard" local bios="Booting from Hard"
@@ -127,6 +133,7 @@ ready() {
} }
forceKillQemu() { forceKillQemu() {
local reason="$1" local reason="$1"
local pid="" local pid=""
local display local display
@@ -143,6 +150,7 @@ forceKillQemu() {
} }
markWindowsBooted() { markWindowsBooted() {
local file="$STORAGE/windows.boot" local file="$STORAGE/windows.boot"
if [ -f "$file" ] || [ ! -f "$BOOT" ]; then if [ -f "$file" ] || [ ! -f "$BOOT" ]; then
@@ -162,19 +170,19 @@ markWindowsBooted() {
} }
cleanupHelpers() { cleanupHelpers() {
local pids=( "${SMB_PID:-}" "${NMB_PID:-}" "${DDN_PID:-}" "${TPM_PID:-}" "${WSD_PID:-}" \ local pids=( "${SMB_PID:-}" "${NMB_PID:-}" "${DDN_PID:-}" "${TPM_PID:-}" "${WSD_PID:-}" \
"${WEB_PID:-}" "${PASST_PID:-}" "${DNSMASQ_PID:-}" "${BALLOONING_PID:-}" ) "${WEB_PID:-}" "${PASST_PID:-}" "${DNSMASQ_PID:-}" "${BALLOONING_PID:-}" )
mKill "${pids[@]}" mKill "${pids[@]}"
closeNetwork
closeNetwork
return 0 return 0
} }
finish() { finish() {
local reason=$1 local reason=$1
touch "$QEMU_END" touch "$QEMU_END"
forceKillQemu "$reason" forceKillQemu "$reason"
@@ -190,6 +198,7 @@ finish() {
fi fi
(( reason != 1 )) && echo && echo " Shutdown completed!" (( reason != 1 )) && echo && echo " Shutdown completed!"
exit "$reason" exit "$reason"
} }
@@ -222,6 +231,7 @@ normalizeTimeout() {
} }
sendAcpiShutdown() { sendAcpiShutdown() {
# Send ACPI shutdown signal # Send ACPI shutdown signal
if [ -S "$QEMU_DIR/monitor.sock" ]; then if [ -S "$QEMU_DIR/monitor.sock" ]; then
nc -q 1 -w 1 -U "$QEMU_DIR/monitor.sock" &> /dev/null <<<'system_powerdown' || : nc -q 1 -w 1 -U "$QEMU_DIR/monitor.sock" &> /dev/null <<<'system_powerdown' || :
@@ -231,17 +241,21 @@ sendAcpiShutdown() {
} }
abortDuringSetup() { abortDuringSetup() {
local code="$1"
local code="$1"
info "Cannot send ACPI signal during $(app) setup, aborting..." info "Cannot send ACPI signal during $(app) setup, aborting..."
sKill "$QEMU_PID" sKill "$QEMU_PID"
if ! waitPidFile "$QEMU_PID" 5; then if ! waitPidFile "$QEMU_PID" 5; then
warn "Timed out while waiting for $(app) to exit!" warn "Timed out while waiting for $(app) to exit!"
fi fi
finish "$code" finish "$code"
} }
waitForShutdown() { waitForShutdown() {
local cnt=0 local cnt=0
local name="$1" local name="$1"
local pid="$2" local pid="$2"