forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt#713 from davidvossel/cleanup-qemu-pid
Ensure qemu process is shutdown if virt-launcher crashes
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |