From c80b18f756df21b1dd67be63a50ac828c3878fef Mon Sep 17 00:00:00 2001 From: "synacktra.work@gmail.com" Date: Sat, 15 Nov 2025 17:28:35 +0530 Subject: [PATCH] fix: graceful shutdown for Windows VM wrapper script - Capture VM process PID after backgrounding tini - Install signal handlers (SIGTERM, SIGINT, SIGHUP, SIGQUIT) to forward signals to VM process - Wait for VM to complete graceful shutdown before exiting - Ensures Windows receives ACPI shutdown signal and has 110 seconds to shut down properly instead of being killed immediately --- libs/qemu-docker/windows/src/entry.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/qemu-docker/windows/src/entry.sh b/libs/qemu-docker/windows/src/entry.sh index 96911911..b15410dc 100644 --- a/libs/qemu-docker/windows/src/entry.sh +++ b/libs/qemu-docker/windows/src/entry.sh @@ -1,5 +1,17 @@ #!/bin/bash +cleanup() { + echo "Received signal, shutting down gracefully..." + if [ -n "$VM_PID" ]; then + kill -TERM "$VM_PID" 2>/dev/null + wait "$VM_PID" 2>/dev/null + fi + exit 0 +} + +# Install trap for signals +trap cleanup SIGTERM SIGINT SIGHUP SIGQUIT + # Create windows.boot file if it doesn't exist (required for proper boot) if [ -d "/storage" -a ! -f "/storage/windows.boot" ]; then echo "Creating windows.boot file in /storage..." @@ -9,6 +21,7 @@ fi # Start the VM in the background echo "Starting Windows VM..." /usr/bin/tini -s /run/entry.sh & +VM_PID=$! echo "Live stream accessible at localhost:8006" echo "Waiting for Windows to boot and CUA computer-server to start..."