From 4374c3fd748957fbfabce1f6d7e8137b3651ae75 Mon Sep 17 00:00:00 2001 From: "Huang, Sophie (sh879n)" Date: Fri, 11 Oct 2019 11:26:18 -0500 Subject: [PATCH] Kill libvirtd proc if any before start libvertd In the startup script of libvirtd, existing libvirt process, if any, is killed before new process is created. Change-Id: If0276353e38896962697a3f451d25d4930745c53 --- libvirt/templates/bin/_libvirt.sh.tpl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libvirt/templates/bin/_libvirt.sh.tpl b/libvirt/templates/bin/_libvirt.sh.tpl index f2b933895..e0b7a5319 100644 --- a/libvirt/templates/bin/_libvirt.sh.tpl +++ b/libvirt/templates/bin/_libvirt.sh.tpl @@ -18,9 +18,19 @@ limitations under the License. set -ex -if [ -n "$(cat /proc/*/comm 2>/dev/null | grep libvirtd)" ]; then - echo "ERROR: libvirtd daemon already running on host" 1>&2 - exit 1 +if [ -n "$(cat /proc/*/comm 2>/dev/null | grep -w libvirtd)" ]; then + set +x + for proc in $(ls /proc/*/comm 2>/dev/null); do + if [ "x$(cat $proc 2>/dev/null | grep -w libvirtd)" == "xlibvirtd" ]; then + set -x + libvirtpid=$(echo $proc | cut -f 3 -d '/') + echo "WARNING: libvirtd daemon already running on host" 1>&2 + echo "$(cat "/proc/${libvirtpid}/status" 2>/dev/null | grep State)" 1>&2 + kill -9 "$libvirtpid" || true + set +x + fi + done + set -x fi rm -f /var/run/libvirtd.pid