diff options
author | Robby Workman <rworkman@slackbuilds.org> | 2014-12-19 23:46:35 -0600 |
---|---|---|
committer | Robby Workman <rworkman@slackbuilds.org> | 2014-12-25 02:10:29 -0600 |
commit | ba6b0592dbdbe52a142cc5aa6757fafa4a2c2b3b (patch) | |
tree | 93a68d355acdeb31f7c808679679b1d6ad8208b0 /libraries/libvirt/rc.libvirt | |
parent | b78946751ddb491fab05017c9517f3b4c64213e7 (diff) | |
download | slackbuilds-ba6b0592dbdbe52a142cc5aa6757fafa4a2c2b3b.tar.gz |
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 <rworkman@slackbuilds.org>
Diffstat (limited to 'libraries/libvirt/rc.libvirt')
-rw-r--r-- | libraries/libvirt/rc.libvirt | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/libraries/libvirt/rc.libvirt b/libraries/libvirt/rc.libvirt index d8ddd63faa..19bf66567e 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 } |