summaryrefslogtreecommitdiff
path: root/community/libvirt
diff options
context:
space:
mode:
authorroot <root@rshg054.dnsready.net>2011-09-15 23:14:42 +0000
committerroot <root@rshg054.dnsready.net>2011-09-15 23:14:42 +0000
commit062d1ba2c4d5de52d97f339c5a3ac1199b8533f6 (patch)
treebd00d2e476e1761b3771b1849a3a207dd8cb5c57 /community/libvirt
parentd5effc9aadfb9ed5890376ca9497eef52fafcf83 (diff)
Thu Sep 15 23:14:42 UTC 2011
Diffstat (limited to 'community/libvirt')
-rw-r--r--community/libvirt/PKGBUILD21
-rw-r--r--community/libvirt/libvirtd-guests.conf.d11
-rwxr-xr-xcommunity/libvirt/libvirtd-guests.rc.d107
3 files changed, 131 insertions, 8 deletions
diff --git a/community/libvirt/PKGBUILD b/community/libvirt/PKGBUILD
index b17d54d64..69c5e52cc 100644
--- a/community/libvirt/PKGBUILD
+++ b/community/libvirt/PKGBUILD
@@ -1,10 +1,10 @@
-# $Id: PKGBUILD 54469 2011-08-18 15:07:52Z bluewind $
+# $Id: PKGBUILD 55591 2011-09-14 14:47:29Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Jonathan Wiersma <archaur at jonw dot org>
pkgname=libvirt
pkgver=0.9.4
-pkgrel=2
+pkgrel=3
pkgdesc="API for controlling virtualization engines (openvz,kvm,qemu,virtualbox,xen,etc)"
arch=('i686' 'x86_64')
url="http://libvirt.org/"
@@ -16,18 +16,13 @@ depends=('e2fsprogs' 'gnutls' 'iptables' 'libxml2' 'parted' 'polkit' 'python2'
makedepends=('pkgconfig' 'lvm2')
optdepends=('bridge-utils: for briged networking (default)'
'dnsmasq: for NAT/DHCP for guests'
- 'kernel26-ovz24: for openvz guests'
'kvm'
- 'lxc'
'openbsd-netcat: for remote management over ssh'
'qemu'
- 'user-mode-linux'
- 'virtualbox_bin'
- 'virtualbox-ose'
- 'xen'
'radvd')
options=('emptydirs' '!libtool')
backup=('etc/conf.d/libvirtd'
+ 'etc/conf.d/libvirtd-guests'
'etc/libvirt/libvirtd.conf'
'etc/libvirt/qemu.conf'
'etc/sasl2/libvirt.conf')
@@ -35,12 +30,16 @@ install="libvirt.install"
source=("http://libvirt.org/sources/$pkgname-$pkgver.tar.gz"
libvirtd.rc.d
libvirtd.conf.d
+ libvirtd-guests.rc.d
+ libvirtd-guests.conf.d
openbsd-netcat-default.patch
unixperms.patch
yajl-2.x.patch)
md5sums=('86b411b11bd23d4af20611699f372af7'
'c43244c40a0437038c82089618e7beaa'
'3ed0e24f5b5e25bf553f5427d64915e6'
+ '6f36bf189ef0e5847038787d13535420'
+ 'bc2971dacdbac967fc3474e50affc345'
'ee7052f3929d5d918236c646a59edebf'
'db95aecdf2ccf3693fef5821cdcb7eba'
'5745bb8d0b254abb7a3528c66e03b0f9')
@@ -74,8 +73,14 @@ build() {
package() {
cd "$srcdir/$pkgname-$pkgver"
+
make DESTDIR="$pkgdir" install
+
install -D -m755 "$srcdir"/libvirtd.rc.d "$pkgdir"/etc/rc.d/libvirtd
install -D -m644 "$srcdir"/libvirtd.conf.d "$pkgdir"/etc/conf.d/libvirtd
+
+ install -D -m755 "$srcdir"/libvirtd-guests.rc.d "$pkgdir"/etc/rc.d/libvirtd-guests
+ install -D -m644 "$srcdir"/libvirtd-guests.conf.d "$pkgdir"/etc/conf.d/libvirtd-guests
+
rm -rf $pkgdir/var/run
}
diff --git a/community/libvirt/libvirtd-guests.conf.d b/community/libvirt/libvirtd-guests.conf.d
new file mode 100644
index 000000000..02a933715
--- /dev/null
+++ b/community/libvirt/libvirtd-guests.conf.d
@@ -0,0 +1,11 @@
+LIBVIRTD_STOP_ACTION=suspend
+
+#LIBVIRTD_URI="-c qemu+ssh://user@host/system"
+LIBVIRTD_URI=""
+
+#LIBVIRTD_BYPASS_CACHE="--bypass-cache"
+LIBVIRTD_BYPASS_CACHE=""
+
+LIBVIRTD_START_DELAY=0
+
+LIBVIRTD_SHUTDOWN_TIMEOUT=3
diff --git a/community/libvirt/libvirtd-guests.rc.d b/community/libvirt/libvirtd-guests.rc.d
new file mode 100755
index 000000000..a97a8d9d1
--- /dev/null
+++ b/community/libvirt/libvirtd-guests.rc.d
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+. /etc/conf.d/libvirtd-guests
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+LIBVIRTD_LISTFILE="/var/state/libvirtd/vm-list"
+
+# get guest state by name
+libvirt_get_guest_state()
+{
+ virsh $LIBVIRTD_URI dominfo "$1" | grep -E '^State:' | awk '{print $2}'
+}
+
+# list IDs of running guests
+libvirt_list()
+{
+ virsh $LIBVIRTD_URI list | awk 'NR > 2 {print $2}'
+}
+
+# suspend guest by name
+libvirt_suspend()
+{
+ virsh $LIBVIRTD_URI $LIBVIRTD_BYPASS_CACHE managedsave "$1" >/dev/null
+ timeout=$LIBVIRTD_SHUTDOWN_TIMEOUT
+ while [ "$timeout" -gt 0 ]; do
+ sleep 1
+ timeout=$((timeout - 1))
+ state=`libvirt_get_guest_state "$1"`
+ [ "x$state" == "xshut" ] && return 0
+ done
+ return 1
+}
+
+# shutdown guest by name
+libvirt_shutdown()
+{
+ virsh $LIBVIRTD_URI shutdown "$1" >/dev/null
+ timeout=$LIBVIRTD_SHUTDOWN_TIMEOUT
+ while [ "$timeout" -gt 0 ]; do
+ sleep 1
+ timeout=$((timeout - 1))
+ state=`libvirt_get_guest_state "$1"`
+ [ "x$state" != "xshut" ] && return 0
+ done
+ return 1
+}
+
+# start guest by name
+libvirt_start()
+{
+ virsh $LIBVIRTD_URI $LIBVIRTD_BYPASS_CACHE start "$1" >/dev/null
+}
+
+# stop all guests
+libvirt_stop_all()
+{
+ mkdir -p `dirname $LIBVIRTD_LISTFILE`
+ echo -n >$LIBVIRTD_LISTFILE
+ for i in `libvirt_list`; do
+ if [ "x$LIBVIRTD_STOP_ACTION" == "xsuspend" ]; then
+ stat_busy "Suspending libvirtd/$i guest"
+ libvirt_suspend "$i"
+ else
+ stat_busy "Shutting libvirtd/$i guest down"
+ libvirt_shutdown "$i"
+ fi
+ [ $? -eq 0 ] && stat_done || stat_fail
+ echo $i >>$LIBVIRTD_LISTFILE
+ done
+}
+
+# start all guests
+libvirt_start_all()
+{
+ if [ -f $LIBVIRTD_LISTFILE ]; then
+ for i in `cat $LIBVIRTD_LISTFILE`; do
+ stat_busy "Starting/resuming libvirtd/$i guest"
+ libvirt_start "$i"
+ [ $? -eq 0 ] && { sleep $LIBVIRTD_START_DELAY; stat_done; } || stat_fail
+ done
+ fi
+ rm -f $LIBVIRTD_LISTFILE
+}
+
+# main
+LC_ALL=C
+LANG=C
+case "$1" in
+ start)
+ libvirt_start_all
+ add_daemon libvirtd-guests
+ ;;
+ stop)
+ libvirt_stop_all
+ rm_daemon libvirtd-guests
+ ;;
+ restart)
+ $0 stop
+ sleep 1
+ $0 start
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|restart}"
+ ;;
+esac
+exit 0