Skip to content

Commit

Permalink
Merge pull request kubevirt#713 from davidvossel/cleanup-qemu-pid
Browse files Browse the repository at this point in the history
Ensure qemu process is shutdown if virt-launcher crashes
  • Loading branch information
davidvossel authored Feb 8, 2018
2 parents c85c60c + d4e0491 commit eb5010d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/virt-launcher/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 [$qemu_pid] exited after after SIGTERM"
exit $rc
fi
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 [$qemu_pid] to exit"
fi

exit $rc

0 comments on commit eb5010d

Please sign in to comment.