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
This commit is contained in:
synacktra.work@gmail.com
2025-11-15 17:28:35 +05:30
parent dbc00bad64
commit c80b18f756

View File

@@ -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..."