diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2012-04-05 02:46:47 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2012-04-05 02:50:12 +0000 |
commit | 0319ade6f072312647197d26bb88cb0a24eda5be (patch) | |
tree | e8d3c521a675a37006f6402e8482c292ead01c04 /main/xen/xendomains.initd | |
parent | fe9b89c13721269c1070cdfaa983afe24cb3d03d (diff) | |
download | aports-0319ade6f072312647197d26bb88cb0a24eda5be.tar.bz2 aports-0319ade6f072312647197d26bb88cb0a24eda5be.tar.xz |
main/xen: use adapted gentoo init.d scripts
Diffstat (limited to 'main/xen/xendomains.initd')
-rw-r--r--[-rwxr-xr-x] | main/xen/xendomains.initd | 153 |
1 files changed, 78 insertions, 75 deletions
diff --git a/main/xen/xendomains.initd b/main/xen/xendomains.initd index 5077d82e03..63d35fc714 100755..100644 --- a/main/xen/xendomains.initd +++ b/main/xen/xendomains.initd @@ -1,114 +1,117 @@ #!/sbin/runscript +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/app-emulation/xen-tools/files/xendomains.initd-r2,v 1.4 2012/01/12 13:40:01 alexxy Exp $ -# See docs/misc/distro_mapping.txt -if [ -d /var/lock/subsys ]; then - LOCKFILE=/var/lock/subsys/xendomains -else - LOCKFILE=/var/lock/xendomains -fi - -if [ -d /etc/sysconfig ]; then - XENDOM_CONFIG=/etc/sysconfig/xendomains -else - XENDOM_CONFIG=/etc/default/xendomains -fi - -if ! [ -r $XENDOM_CONFIG ]; then - eend 1; - echo "$XENDOM_CONFIG not existing"; - return 1; -fi - -. $XENDOM_CONFIG +extra_commands="status" depend() { - need xencommons - after net xend + need xenstored + after dhcp xend xenconsoled } get_domname() { local name_from_file=$(sed -rn 's/^name\W*=\W*\"?([[:alnum:]_\.-]+)\"?\W*;?/\1/p' "${1}" | tail -n 1) - if [[ -z ${name_from_file} ]] ; then + if [ -z ${name_from_file} ]; then basename "${1}" else - echo ${name_from_file} + echo ${name_from_file} fi } is_running() { - /usr/sbin/$CMD list "${1}" >/dev/null 2>&1 + /usr/sbin/xl list "${1}" >/dev/null 2>&1 } -check_xen() { - CMD=xm - /usr/sbin/$CMD list &> /dev/null - if test $? -ne 0 - then - CMD=xl - fi - - /usr/sbin/$CMD list &> /dev/null - if test $? -ne 0 - then - eend 1; - echo "Could not find xl or xm"; - return 1; - fi +using_screen() { + yesno "${SCREEN}" +} - # Correct exit code would probably be 5, but it's enough - # if xend complains if we're not running as privileged domain - if ! [ -e /proc/xen/privcmd ]; then - eend 1; - echo "Could not find /proc/xen/privcmd"; - return 1; - fi +set_screen_cmd() { + screen_cmd="screen -c ${SCREENRC:-/dev/null} -q -r ${SCREEN_NAME:=xen} -X" } start() { - einfo "Starting Xen domains in ${AUTODIR:=/etc/xen/auto}" - - check_xen - + set_screen_cmd + + einfo "Starting Xen domains from ${AUTODIR:=/etc/xen/auto}" + if using_screen ; then + ebegin "Creating screen session to hold domain consoles" + ( screen -c ${SCREENRC:-/dev/null} -d -m -S ${SCREEN_NAME} -t dom0 \ + && ${screen_cmd} zombie dr \ + && logrotate -f /etc/xen/xen-consoles.logrotate \ + && ${screen_cmd} logfile /var/log/xen-consoles/%t.log \ + && ${screen_cmd} logfile flush ${SCREEN_LOG_INTERVAL:-1} \ + && ${screen_cmd} log on \ + && ${screen_cmd} deflog on ) >/dev/null + if [ $? -ne 0 ] ; then + eend 1 + return 1 + else + eend + fi + fi + # Create all domains with config files in AUTODIR. for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do name=$(get_domname ${dom}) if ! is_running ${name} ; then ebegin " Starting domain ${name}" - /usr/sbin/$CMD create --quiet --defconfig ${dom} >/dev/null 2>&1 + if using_screen ; then + ${screen_cmd} screen -t ${name} xl create ${dom} -c + else + xl create --quiet ${dom} + fi eend $? else - einfo " Not starting ${name} - already running." + einfo " Not starting domain ${name} - already running" fi done } stop() { - einfo "Stopping Xen domains in ${AUTODIR:=/etc/xen/auto}" - - check_xen - - for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do - name=$(get_domname ${dom}) - if is_running ${name} ; then - ebegin " Sending shutdown signal to ${name}" - /usr/sbin/$CMD shutdown ${name} >/dev/null 2>&1 - eend $? - fi - done - - for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do - name=$(get_domname ${dom}) - if is_running ${name} ; then - ebegin " Waiting for domain ${name} to shutdown" - /usr/sbin/$CMD shutdown --wait ${name} >/dev/null 2>&1 + set_screen_cmd + + einfo "Shutting down Xen domains from ${AUTODIR:=/etc/xen/auto}" + # Stop all domains with config files in AUTODIR. + DOMAINS="$(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort -r)" + + if yesno "$PARALLEL_SHUTDOWN"; then + for dom in $DOMAINS ; do + name=$(get_domname ${dom}) + if is_running ${name} ; then + ebegin " Asking domain ${name} to shutdown in the background..." + xl shutdown -w ${name} >/dev/null & + else + einfo " Not stopping domain ${name} - not running" + fi + done + einfo " Waiting for shutdown of domains that are still running" + wait + eend $? + else + for dom in $DOMAINS ; do + name=$(get_domname ${dom}) + if is_running ${name} ; then + ebegin " Waiting for domain ${name} to shutdown" + xl shutdown -w ${name} >/dev/null + eend $? + else + einfo " Not stopping domain ${name} - not running" + fi + done + fi + if using_screen ; then + if ${screen_cmd} sleep 0 >/dev/null 2>&1 ; then + ebegin "Closing screen session ${SCREEN_NAME}" + ${screen_cmd} quit eend $? else - einfo " Not stopping ${name} - not running." + eend 0 fi - done + fi } status() { - check_xen - /usr/sbin/$CMD list + /usr/sbin/xl list } |