From 83cea7b77f75e99f918c391d5f3beb7d01218ce1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 14 Apr 2023 15:37:27 +0200 Subject: [PATCH] Prevent re-entry --- power.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/power.sh b/power.sh index 6376e76..89ab39f 100644 --- a/power.sh +++ b/power.sh @@ -5,9 +5,13 @@ set -eu QEMU_MONPORT=7100 QEMU_POWERDOWN_TIMEOUT=8 + _QEMU_PID=/run/qemu.pid _QEMU_SHUTDOWN_COUNTER=/run/qemu.counter +rm -f "${_QEMU_PID}" +rm -f "${_QEMU_SHUTDOWN_COUNTER}" + # Allows for troubleshooting signals sent to the process _trap(){ func="$1" ; shift @@ -19,7 +23,9 @@ _trap(){ _graceful_shutdown(){ local QEMU_MONPORT="${QEMU_MONPORT:-7100}" - local QEMU_POWERDOWN_TIMEOUT="${QEMU_POWERDOWN_TIMEOUT:-120}" + local QEMU_POWERDOWN_TIMEOUT="${QEMU_POWERDOWN_TIMEOUT:-8}" + + [ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return set +e echo "Received $1 signal, shutting down..." @@ -43,7 +49,7 @@ _graceful_shutdown(){ done echo "Quitting..." - echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}">/dev/null || true + echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT:-7100}">/dev/null || true return }