diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 06d2a1c..28af5f1 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -11,4 +11,4 @@ jobs: - name: Run ShellCheck uses: ludeeus/action-shellcheck@master env: - SHELLCHECK_OPTS: -x -e SC2001 -e SC2002 -e SC2223 -e SC2034 -e SC2064 -e SC2317 + SHELLCHECK_OPTS: -x -e SC2001 -e SC2002 -e SC2223 -e SC2034 -e SC2064 -e SC2317 -e SC2093 diff --git a/readme.md b/readme.md index 32ac017..76e897a 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,6 @@ QEMU in a docker container using KVM acceleration. - Multi-platform - KVM acceleration - - Graceful shutdown ## Usage @@ -38,7 +37,6 @@ services: ports: - 22:22 restart: on-failure - stop_grace_period: 1m ``` Via `docker run` 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" diff --git a/run/run.sh b/run/run.sh index 3d25082..ab3e472 100755 --- a/run/run.sh +++ b/run/run.sh @@ -38,9 +38,6 @@ fi # Initialize network . /run/network.sh -# Configure shutdown -. /run/power.sh - KVM_ERR="" KVM_OPTS="" @@ -68,21 +65,11 @@ MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}" SERIAL_OPTS="-serial mon:stdio -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3" EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0 -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0" -ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS} ${ARGUMENTS}" +ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS} ${ARGUMENTS}" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') trap - ERR -set -m -( - [[ "${DEBUG}" == [Yy1]* ]] && info "$VERS" && set -x - qemu-system-x86_64 ${ARGS:+ $ARGS} & echo $! > "${_QEMU_PID}" - { set +x; } 2>/dev/null -) -set +m - -#if (( KERNEL > 5 )) || ( (( KERNEL == 5 )) && (( MINOR > 2 )) ); then -# pidwait -F "${_QEMU_PID}" & wait $! -#else - -tail --pid "$(cat "${_QEMU_PID}")" --follow /dev/null & wait $! +[[ "${DEBUG}" == [Yy1]* ]] && info "$VERS" && set -x +exec qemu-system-x86_64 ${ARGS:+ $ARGS} +{ set +x; } 2>/dev/null