libraries/libvirt: Properly initialize $count in rc.libvirt

This commit also contains some other minor fixups.

Signed-off-by: Robby Workman <rworkman@slackbuilds.org>
This commit is contained in:
Sebastian Arcus 2018-03-05 23:18:02 -06:00 committed by Willy Sudiarto Raharjo
parent 14c188e5af
commit 480d09ca14
1 changed files with 20 additions and 6 deletions

View File

@ -34,7 +34,11 @@ guests_shutdown() {
/usr/sbin/virsh shutdown $machine &
done
echo -n "Waiting for guests to finish shutting down"
sleep 2
echo -n "Waiting for guests to finish shutting down..."
count=0
while [ $(/usr/sbin/virsh list --name --state-running | grep -v ^$ | wc -l) -gt "0" ]; do
if [ "$count" -ge "$TIMEOUT" ];then
@ -49,13 +53,17 @@ guests_shutdown() {
if [ $(/usr/sbin/virsh list --name --state-running | grep -v ^$ | wc -l) -gt "0" ];then
echo -n "The following guests are still running, destroying them: "
echo -n "The following guests are still running after $TIMEOUT seconds; destroying them: "
for machine in $(/usr/sbin/virsh list --name --state-running | grep -v ^$) ; do
/usr/sbin/virsh destroy $machine
echo -n "$machine "
done
sleep 2
else
# add back the seconds we waited before starting the count
count=$(expr $count + 2)
echo "Shutdown of guests took $count seconds..."
fi
}
@ -65,13 +73,15 @@ guests_managedsave() {
# apply managedsave on running and paused machines (as we can't distinguish between
# the two states while managedsave is being applied, so won't know when to finish waiting)
count=0
for machine in $(/usr/sbin/virsh list --name | grep -v ^$) ; do
/usr/sbin/virsh managedsave $machine &
done
echo -n "Waiting for managedsave to finish on all guests"
sleep 2
echo -n "Waiting for managedsave to finish on all guests..."
count = 0
while [ $(/usr/sbin/virsh list --name | grep -v ^$ | wc -l) -gt "0" ]; do
if [ "$count" -ge "$TIMEOUT" ];then
@ -86,13 +96,17 @@ guests_managedsave() {
if [ $(/usr/sbin/virsh list --name | grep -v ^$ | wc -l) -gt "0" ];then
echo -n "The following guests are still running, destroying them: "
echo -n "Following guests are still running after $TIMEOUT seconds, destroying them: "
for machine in $(/usr/sbin/virsh list --name | grep -v ^$) ; do
/usr/sbin/virsh destroy $machine
echo -n "$machine "
done
sleep 2
else
# add back the seconds we waited before starting the count
count=$(expr $count + 2)
echo "Guests managed save took $count seconds..."
fi
}