mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-12-16 15:20:37 +08:00
Implemented API for guest communication
This allows to send the shutdown command from the host to the guest
This commit is contained in:
37
power.sh
37
power.sh
@@ -4,7 +4,7 @@ set -eu
|
||||
# Configure QEMU for graceful shutdown
|
||||
|
||||
QEMU_MONPORT=7100
|
||||
QEMU_POWERDOWN_TIMEOUT=30
|
||||
QEMU_POWERDOWN_TIMEOUT=50
|
||||
_QEMU_PID=/run/qemu.pid
|
||||
_QEMU_SHUTDOWN_COUNTER=/run/qemu.counter
|
||||
|
||||
@@ -22,22 +22,31 @@ _graceful_shutdown(){
|
||||
local QEMU_POWERDOWN_TIMEOUT="${QEMU_POWERDOWN_TIMEOUT:-120}"
|
||||
|
||||
set +e
|
||||
echo "Received $1 signal.."
|
||||
echo "Received $1 signal, shutting down..."
|
||||
echo 0 > "${_QEMU_SHUTDOWN_COUNTER}"
|
||||
|
||||
FILE="${IMG}/agent.ver"
|
||||
[ ! -f "$FILE" ] && echo "1" > "$FILE"
|
||||
AGENT_VERSION=$(cat "${FILE}")
|
||||
|
||||
# Don't send the powerdown signal because Synology ignores it
|
||||
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}">/dev/null
|
||||
|
||||
if ((AGENT_VERSION < 2)); then
|
||||
echo "Please update the agent to allow gracefull shutdowns..."
|
||||
pkill -f qemu-system-x86_64
|
||||
else
|
||||
# Send a NMI interrupt which will be detected by the agent
|
||||
echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}">/dev/null
|
||||
# Send shutdown command to guest agent tools instead via serial port
|
||||
RESPONSE=$(curl -s -m 2 -S http://127.0.0.1:2210/write?command=6 2>&1)
|
||||
|
||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
||||
|
||||
echo "Could not send shutdown command to guest, error: $RESPONSE"
|
||||
|
||||
FILE="${IMG}/agent.ver"
|
||||
[ ! -f "$FILE" ] && echo "1" > "$FILE"
|
||||
AGENT_VERSION=$(cat "${FILE}")
|
||||
|
||||
if ((AGENT_VERSION < 2)); then
|
||||
echo "Please update the agent to allow gracefull shutdowns..."
|
||||
pkill -f qemu-system-x86_64
|
||||
else
|
||||
# Send a NMI interrupt which will be detected by the kernel
|
||||
echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}">/dev/null
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
while [ "$(cat ${_QEMU_SHUTDOWN_COUNTER})" -lt "${QEMU_POWERDOWN_TIMEOUT}" ]; do
|
||||
@@ -54,7 +63,7 @@ _graceful_shutdown(){
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Killing VM.."
|
||||
echo "Quitting..."
|
||||
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}">/dev/null || true
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user