From 623ea143560159d568461f85481bf34f551301ba Mon Sep 17 00:00:00 2001 From: David Vossel Date: Tue, 6 Feb 2018 13:27:37 -0500 Subject: [PATCH 1/2] Ensure qemu process is shutdown if virt-launcher crashes Signed-off-by: David Vossel --- cmd/virt-launcher/entrypoint.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cmd/virt-launcher/entrypoint.sh b/cmd/virt-launcher/entrypoint.sh index 7a3e2285a479..7c3e13192533 100755 --- a/cmd/virt-launcher/entrypoint.sh +++ b/cmd/virt-launcher/entrypoint.sh @@ -1,2 +1,29 @@ #!/bin/bash ./virt-launcher $@ +rc=$? + +echo "virt-launcher exited with code $rc" + +# if the qemu pid outlives virt-launcher because virt-launcher +# segfaulted/panicked/etc... then make sure we perform a sane +# shutdown of the qemu process before exitting. +qemu_pid=$(pgrep -u qemu) +if [ -n "$qemu_pid" ]; then + echo "qemu pid outlived virt-launcher process. Sending SIGTERM" + kill -SIGTERM $qemu_pid + + # give the pid 10 seconds to exit. + for x in $(seq 1 10); do + if ! [ -d /proc/$qemu_pid ]; then + echo "qemu pid exited after after SIGTERM" + exit $rc + fi + echo "waiting for qemu pid to exit" + sleep 1 + done + + # if we got here, the pid never exitted gracefully. + echo "timed out waiting for qemu pid to exit" +fi + +exit $rc From d4e049154b1ec39edc562c9b617693fc3c47bf39 Mon Sep 17 00:00:00 2001 From: David Vossel Date: Thu, 8 Feb 2018 12:59:13 -0500 Subject: [PATCH 2/2] echo qemu pid in entrypoint shutdown logic Signed-off-by: David Vossel --- cmd/virt-launcher/entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/virt-launcher/entrypoint.sh b/cmd/virt-launcher/entrypoint.sh index 7c3e13192533..18237fc50356 100755 --- a/cmd/virt-launcher/entrypoint.sh +++ b/cmd/virt-launcher/entrypoint.sh @@ -15,15 +15,15 @@ if [ -n "$qemu_pid" ]; then # give the pid 10 seconds to exit. for x in $(seq 1 10); do if ! [ -d /proc/$qemu_pid ]; then - echo "qemu pid exited after after SIGTERM" + echo "qemu pid [$qemu_pid] exited after after SIGTERM" exit $rc fi - echo "waiting for qemu pid to exit" + echo "waiting for qemu pid [$qemu_pid] to exit" sleep 1 done # if we got here, the pid never exitted gracefully. - echo "timed out waiting for qemu pid to exit" + echo "timed out waiting for qemu pid [$qemu_pid] to exit" fi exit $rc