This commit is contained in:
Kroese 2023-04-17 05:13:46 +02:00 committed by GitHub
parent 4e5a48422c
commit f14d100e43

View File

@ -21,12 +21,10 @@ _trap(){
_graceful_shutdown(){ _graceful_shutdown(){
local QEMU_MONPORT="${QEMU_MONPORT:-7100}"
local QEMU_POWERDOWN_TIMEOUT="${QEMU_POWERDOWN_TIMEOUT:-50}"
[ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return [ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return
set +e set +e
echo echo
echo "Received $1 signal, shutting down..." echo "Received $1 signal, shutting down..."
echo 0 > "${_QEMU_SHUTDOWN_COUNTER}" echo 0 > "${_QEMU_SHUTDOWN_COUNTER}"
@ -47,14 +45,18 @@ _graceful_shutdown(){
AGENT_VERSION=$(cat "${AGENT}") AGENT_VERSION=$(cat "${AGENT}")
if ((AGENT_VERSION < 2)); then if ((AGENT_VERSION < 2)); then
echo echo
echo "Please update the agent to allow gracefull shutdowns..." echo "Please update the agent to allow gracefull shutdowns..."
pkill -f qemu-system-x86_64 pkill -f qemu-system-x86_64
else else
# Send a NMI interrupt which will be detected by the kernel # Send a NMI interrupt which will be detected by the kernel
echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null
fi
fi
fi fi
while [ "$(cat ${_QEMU_SHUTDOWN_COUNTER})" -lt "${QEMU_POWERDOWN_TIMEOUT}" ]; do while [ "$(cat ${_QEMU_SHUTDOWN_COUNTER})" -lt "${QEMU_POWERDOWN_TIMEOUT}" ]; do
@ -69,6 +71,7 @@ _graceful_shutdown(){
#echo "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})" #echo "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})"
fi fi
done done
echo echo