Index: sysutils/xen-tools/Makefile =================================================================== --- sysutils/xen-tools/Makefile +++ sysutils/xen-tools/Makefile @@ -22,8 +22,8 @@ RUN_DEPENDS= seabios>0:misc/seabios DOCS_BUILD_DEPENDS=markdown:textproc/markdown +USE_RC_SUBR= xendomains OPTIONS_DEFINE= DOCS SPICE -OPTIONS_DEFAULT= DOCS OPTIONS_SUB= yes SPICE_DESC= Enable SPICE protocol for QEMU Index: sysutils/xen-tools/files/xendomains.in =================================================================== --- sysutils/xen-tools/files/xendomains.in +++ sysutils/xen-tools/files/xendomains.in @@ -0,0 +1,77 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: xendomains +# REQUIRE: FILESYSTEMS xencommons + +. /etc/rc.subr + +name="xendomains" +desc="Manage Xen Domains" +rcvar="xendomains_enable" + +start_cmd="xendomains_start" +stop_cmd="xendomains_stop" +status_cmd="xendomains_status" +extra_commands="status" +: ${xendomains_cmd:=/usr/local/sbin/xl} +: ${xendomains_dir:=/usr/local/etc/xen/auto} +: ${xen_shutdown_wait:=30} +: ${xen_destroy_wait:=60} + +xendomains_status() +{ + ${xendomains_cmd} list | awk ' + (FNR <= 2) { next } + ($5 !~ /s/) { s = s " " $1 } + END { sub(" *", "", s); print s }' | tr ' ' '\n' +} + +xendomains_start() +{ + echo 'Starting Xen Domains' + for domain in ${xendomains_dir}/* ; do + ${xendomains_cmd} create ${domain} + done +} + +xendomains_stop() +{ + echo 'Stopping Xen Domains' + + xendomains_status | while read domain ; do + echo Stopping Xen domain ${domain} + ${xendomains_cmd} shutdown -F ${domain} + done + + echo "Waiting ${xen_shutdown_wait} seconds for Xen Domain poweroff" + sleep ${xen_shutdown_wait} + + if [ $( xendomains_status | wc -l ) -gt 1 ] ; then + echo 'Powering off remaining Xen Domains' + xendomains_status | while read domain ; do + echo Stopping Xen domain ${domain} + ${xendomains_cmd} shutdown -F ${domain} + done + fi + + if [ $( xendomains_status | wc -l ) -gt 1 ] ; then + echo "Waiting ${xen_destroy_wait} seconds for Xen Domain destruction" + sleep ${xen_destroy_wait} + if [ $( xendomains_status | wc -l ) -gt 1 ] ; then + xendomains_status | while read domain ; do + echo Destroying Xen domain ${domain} + ${xendomains_cmd} destroy ${domain} + done + fi + fi + + if [ $( xendomains_status | wc -l ) -gt 1 ] ; then + echo 'The following Xen Domains could not be destroyed:' + xendomains_status + fi +} + +run_rc_command "$1"