From 9f85b5182ff330e056af054687028c1b2a4f188d Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 25 Sep 2023 01:16:43 +0200 Subject: [PATCH] Delete run/power.sh --- run/power.sh | 60 ---------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 run/power.sh diff --git a/run/power.sh b/run/power.sh deleted file mode 100644 index 4e4f95f..0000000 --- a/run/power.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail - -# Configure QEMU for graceful shutdown - -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}" - -_trap(){ - func="$1" ; shift - for sig ; do - trap "$func $sig" "$sig" - done -} - -_graceful_shutdown() { - - set +e - - [ ! -f "${_QEMU_PID}" ] && return - [ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return - - echo && info "Received $1 signal, shutting down..." - echo 0 > "${_QEMU_SHUTDOWN_COUNTER}" - - # Send the shutdown (system_powerdown) command to the QMP monitor - echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null - - while [ "$(cat ${_QEMU_SHUTDOWN_COUNTER})" -lt "${QEMU_POWERDOWN_TIMEOUT}" ]; do - - # Increase the counter - echo $(($(cat ${_QEMU_SHUTDOWN_COUNTER})+1)) > ${_QEMU_SHUTDOWN_COUNTER} - - # Try to connect to qemu - if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 ; then - - sleep 1 - info "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})" - - fi - - done - - echo && echo "❯ Quitting..." - echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true - - closeNetwork - - return -} - -_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT - -MON_OPTS="-monitor telnet:localhost:${QEMU_MONPORT},server,nowait,nodelay"