From ba6b0592dbdbe52a142cc5aa6757fafa4a2c2b3b Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Fri, 19 Dec 2014 23:46:35 -0600 Subject: libraries/libvirt: Make rc.libvirt more robust Detecting running domains by grepping for "running" isn't very effective for non-english strings, so let's fix that. Since I was already there, I cleaned up a few more nits. Thanks to Mathieu Bouillaguet for the report and solution. Signed-off-by: Robby Workman --- libraries/libvirt/libvirt.SlackBuild | 2 +- libraries/libvirt/rc.libvirt | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'libraries/libvirt') diff --git a/libraries/libvirt/libvirt.SlackBuild b/libraries/libvirt/libvirt.SlackBuild index c8a17ffd6cf9c..aee62631a476c 100644 --- a/libraries/libvirt/libvirt.SlackBuild +++ b/libraries/libvirt/libvirt.SlackBuild @@ -6,7 +6,7 @@ PRGNAM=libvirt VERSION=${VERSION:-1.2.11} -BUILD=${BUILD:-1} +BUILD=${BUILD:-2} TAG=${TAG:-_SBo} if [ -z "$ARCH" ]; then diff --git a/libraries/libvirt/rc.libvirt b/libraries/libvirt/rc.libvirt index d8ddd63faa80c..19bf66567e98b 100644 --- a/libraries/libvirt/rc.libvirt +++ b/libraries/libvirt/rc.libvirt @@ -18,31 +18,31 @@ OPTS=${OPTS:-" -v -f /etc/libvirt/libvirtd.conf -p $PIDFILE "} check_running_machines() { - i=0 + count=0 - for j in `/usr/sbin/virsh list | grep running | awk '{print $2;}'` ; do - /usr/sbin/virsh shutdown $j + for machine in $(virsh list --name --state-running | grep -v ^$) ; do + /usr/sbin/virsh shutdown $machine done echo -n "Waiting machines" - while [ $(/usr/sbin/virsh list | grep running | wc -l) -gt "0" ]; do - if [ "$i" -ge "$TIMEOUT" ];then + while [ $(virsh list --name --state-running | grep -v ^$ | wc -l) -gt "0" ]; do + if [ "$count" -ge "$TIMEOUT" ];then break fi echo -n "." - i=`expr $i + 1` + count=$(expr $count + 1) sleep 1 done echo "" - if [ $(/usr/sbin/virsh list | grep running | wc -l) -gt "0" ];then + if [ $(virsh list --name --state-running | grep -v ^$ | wc -l) -gt "0" ];then echo -n "The following machines are still running, forcing shutdown: " - for j in `/usr/sbin/virsh list | grep running | awk '{print $2;}'` ; do - /usr/sbin/virsh destroy $j - echo -n "$j " + for machine in $(virsh list --name --state-running | grep -v ^$) ; do + /usr/sbin/virsh destroy $machine + echo -n "$machine " done echo "" @@ -67,10 +67,10 @@ check_processor() { MODULES="$MODULES kvm_amd kvm" fi - check=`expr $check + $?` + check=$(expr $check + $?) if [ $check -eq "2" ];then - echo "Your systems does not support KVM!" + echo "Your system does not support KVM!" fi } @@ -95,10 +95,10 @@ stop() { check_running_machines check_processor echo "Stopping libvirtd..." - for i in $(/usr/sbin/virsh net-list | tail -n +3 | awk '{print $1}'); do - /usr/sbin/virsh net-destroy "$i" + for network in $(/usr/sbin/virsh net-list | tail -n +3 | awk '{print $1}'); do + /usr/sbin/virsh net-destroy "$network" done - kill -TERM `cat $PIDFILE` + kill -TERM $(cat $PIDFILE) sleep 3 /sbin/modprobe -ra $MODULES 2>/dev/null } -- cgit v1.2.3