summaryrefslogtreecommitdiffstats
path: root/libraries/libvirt/rc.libvirt
diff options
context:
space:
mode:
author ponce2012-07-30 13:21:07 +0200
committer Robby Workman2012-08-21 15:55:34 +0200
commitbc9e450e41d394a8dfc88fd74cda3bee7f0b11b5 (patch)
tree7a96daf8a5b566715bf40fda9e8e8425a26a83a7 /libraries/libvirt/rc.libvirt
parenta951d7375f4587879607e5ec6c1beda13478a3d0 (diff)
downloadslackbuilds-bc9e450e41d394a8dfc88fd74cda3bee7f0b11b5.tar.gz
libraries/libvirt: Updated for version 0.9.13.
This commit also adds some configure options parameters (disabled debug too), some details in the README, and an rc.libvirt init script... Signed-off-by: Robby Workman <rworkman@slackbuilds.org>
Diffstat (limited to 'libraries/libvirt/rc.libvirt')
-rw-r--r--libraries/libvirt/rc.libvirt106
1 files changed, 106 insertions, 0 deletions
diff --git a/libraries/libvirt/rc.libvirt b/libraries/libvirt/rc.libvirt
new file mode 100644
index 0000000000..1cdea9a7ea
--- /dev/null
+++ b/libraries/libvirt/rc.libvirt
@@ -0,0 +1,106 @@
+#!/bin/bash
+
+MODULES="tun vhost_net"
+PIDFILE="/var/run/libvirtd.pid"
+TIMEOUT=${TIMEOUT:-40}
+OPTS=${OPTS:-" -v -f /etc/libvirt/libvirtd.conf "}
+
+check_running_machines() {
+
+ i=0
+
+ for j in `/usr/sbin/virsh list | grep running | awk '{print $2;}'` ; do
+ /usr/sbin/virsh shutdown $j
+ done
+
+ echo -n "Waiting machines"
+
+ while [ $(/usr/sbin/virsh list | grep running | wc -l) -gt "0" ]; do
+ if [ "$i" -ge "$TIMEOUT" ];then
+ break
+ fi
+ echo -n "."
+ i=`expr $i + 1`
+ sleep 1
+ done
+
+ echo ""
+
+ if [ $(/usr/sbin/virsh list | grep running | 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 "
+ done
+
+ echo ""
+ sleep 2
+ fi
+
+}
+
+check_processor() {
+
+ egrep 'vmx' /proc/cpuinfo > /dev/null
+
+ if [ "$?" -eq "0" ];then
+ MODULES="$MODULES kvm_intel kvm"
+ fi
+
+ check=$?
+
+ egrep 'svm' /proc/cpuinfo > /dev/null
+
+ if [ "$?" -eq "0" ];then
+ MODULES="$MODULES kvm_amd kvm"
+ fi
+
+ check=`expr $check + $?`
+
+ if [ $check -eq "2" ];then
+ echo "Your systems does not support KVM!"
+ fi
+
+}
+
+start() {
+ if [ -f $PIDFILE ];then
+ echo "libvirt is already running..."
+ exit 1
+ fi
+ echo "Starting libvirtd..."
+ check_processor
+ modprobe -a $MODULES
+ libvirtd -d -l $OPTS
+}
+
+stop() {
+ if [ ! -f $PIDFILE ];then
+ echo "libvirt is not running..."
+ exit 2
+ fi
+ check_running_machines
+ check_processor
+ echo "Stopping libvirtd..."
+ kill -TERM `cat $PIDFILE`
+ modprobe -ra $MODULES
+}
+
+case $1 in
+start)
+ start
+ ;;
+stop)
+ stop
+ ;;
+restart)
+ stop
+ sleep 1
+ start
+ ;;
+*)
+ echo "Usage: $0 (start|stop|restart)"
+ ;;
+esac
+