Bastian Blank
2012-Jan-31 13:09 UTC
[Pkg-xen-changes] r955 - in trunk/xen/debian: . templates
Author: waldi Date: Tue Jan 31 13:09:30 2012 New Revision: 955 Log: * debian/changelog: Update. * debian/rules.real - Call dh_installexamples always. - Install xen-utils-common. * debian/templates/control.main.in: Add xen-utils-common. * debian/xen-utils-common.*: Add. Added: trunk/xen/debian/xen-utils-common.README.Debian - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.README.Debian trunk/xen/debian/xen-utils-common.examples - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.examples trunk/xen/debian/xen-utils-common.install - copied, changed from r937, trunk/xen-common/debian/xen-utils-common.install trunk/xen/debian/xen-utils-common.postinst - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.postinst trunk/xen/debian/xen-utils-common.postrm - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.postrm trunk/xen/debian/xen-utils-common.preinst - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.preinst trunk/xen/debian/xen-utils-common.xen.default - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.xen.default trunk/xen/debian/xen-utils-common.xend.default - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.xend.default trunk/xen/debian/xen-utils-common.xend.init - copied unchanged from r944, trunk/xen-common/debian/xen-utils-common.xend.init trunk/xen/debian/xen-utils-common.xendomains.default - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.xendomains.default trunk/xen/debian/xen-utils-common.xendomains.init - copied unchanged from r937, trunk/xen-common/debian/xen-utils-common.xendomains.init Modified: trunk/xen/debian/changelog trunk/xen/debian/rules.real trunk/xen/debian/templates/control.main.in Modified: trunk/xen/debian/changelog =============================================================================--- trunk/xen/debian/changelog Tue Jan 31 13:06:27 2012 (r954) +++ trunk/xen/debian/changelog Tue Jan 31 13:09:30 2012 (r955) @@ -1,3 +1,11 @@ +xen (4.1.2-3) UNRELEASED; urgency=low + + * Merge xen-common source package. + * Remove xend wrapper, it should not be called by users. + * Support xl in init script. + + -- Bastian Blank <waldi at debian.org> Tue, 31 Jan 2012 14:07:41 +0100 + xen (4.1.2-2) unstable; urgency=low [ Jon Ludlam ] Modified: trunk/xen/debian/rules.real =============================================================================--- trunk/xen/debian/rules.real Tue Jan 31 13:06:27 2012 (r954) +++ trunk/xen/debian/rules.real Tue Jan 31 13:09:30 2012 (r955) @@ -25,6 +25,7 @@ binary-arch-flavour: install-hypervisor_$(ARCH)_$(FLAVOUR) binary-indep: install-docs +binary-indep: install-utils-common build-arch: $(STAMPS_DIR)/build-utils_$(ARCH) build-flavour: $(STAMPS_DIR)/build-hypervisor_$(ARCH)_$(FLAVOUR) @@ -96,6 +97,7 @@ install-base: dh_installchangelogs -XChangelog dh_installdocs + dh_installexamples dh_compress dh_fixperms dh_installdeb @@ -213,6 +215,21 @@ dh_shlibdeps +$(MAKE_SELF) install-base +install-utils-common: SOURCE_DIR = $(BUILD_DIR)/build-docs +install-utils-common: DIR = $(BUILD_DIR)/install-utils-common +install-utils-common: PACKAGE_NAME = xen-utils-common +install-utils-common: DH_OPTIONS = -p$(PACKAGE_NAME) +install-utils-common: export DESTDIR = $(CURDIR)/$(DIR) +install-utils-common: $(STAMPS_DIR)/build-docs + dh_testdir + dh_testroot + dh_prep + $(MAKE) -C $(SOURCE_DIR)/tools/examples install-configs + $(MAKE) -C $(SOURCE_DIR)/tools/hotplug/common install-scripts + $(MAKE) -C $(SOURCE_DIR)/tools/hotplug/Linux install-udev install-scripts UDEV_RULES_DIR=/lib/udev + dh_install --sourcedir=$(DIR) + +$(MAKE_SELF) install-base + install-xenstore-utils_$(ARCH): DIR = $(BUILD_DIR)/install-utils_$(ARCH) install-xenstore-utils_$(ARCH): PACKAGE_NAME = xenstore-utils install-xenstore-utils_$(ARCH): DH_OPTIONS = -p$(PACKAGE_NAME) Modified: trunk/xen/debian/templates/control.main.in =============================================================================--- trunk/xen/debian/templates/control.main.in Tue Jan 31 13:06:27 2012 (r954) +++ trunk/xen/debian/templates/control.main.in Tue Jan 31 13:09:30 2012 (r955) @@ -49,3 +49,10 @@ This package contains the ocaml findlib packages for compiling applications that are designed to control the Xen hypervisor. +Package: xen-utils-common +Architecture: all +Depends: gawk, lsb-base, udev, xenstore-utils, ${misc:Depends} +Description: Xen administrative tools - common files + The userspace tools to manage a system virtualized through the Xen virtual + machine monitor. + Copied: trunk/xen/debian/xen-utils-common.README.Debian (from r937, trunk/xen-common/debian/xen-utils-common.README.Debian) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.README.Debian Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.README.Debian) @@ -0,0 +1,53 @@ +Xen for Debian +=============+ +Config behaviour +---------------- + +The Debian packages changes the behaviour of some config options. + +The options "kernel", "initrd" and "loader" searches in the Xen private boot +directory (/usr/lib/xen-$version/boot) first. "bootloader" and "device_model" +also searches the Xen private bin directory (/usr/lib/xen-$version/bin). This +means that the following entries will properly find anything: + loader = ''hvmloader'' + bootloader = ''pygrub'' + +Network setup +------------- + +The Debian package of Xen don''t change the network setup in any way. This +differs from the upstream version, which overwrites the main network card +(eth0) with a bridge setup and may break the network at this point.. + +To setup a bridge please follow the instructions in the manpage for +bridge-utils-interfaces(5). + +You can also change the /etc/xen/xend-config.sxp file and re-enable the Xen +included network setup by adding + (network-script network-bridge) +to the file. But please note that this may or may not work. + +Loop devices +------------ + +If you plan hosting virtual domains with file backed block devices (ie. the +ones xen-tools creates by default) be careful about two issues: + +1. Maximum number of loop devices + By default the loop driver supports a maximum of 8 loop devices. Of + course since every Xen domain uses at least two (one for the data and one + for the swap) this number is absolutely insufficient. You should increase + it by adding a file named local-loop in /etc/modprobe.d containing the + string "options loop max_loop=128", if the loop driver is compiled as a + module, or by appending the string max_loop=128 to your kernel parameters + if the driver is in-kernel. Of course you can increase or decrease the + number 128 as you see fit. + +2. Driver loading (only if loop is compiled as a module) + Normally the loop driver gets loaded when the first loop device is + accessed. When using udev, though, the loop devices get created only + after the driver gets loaded. This means that Xen will fail if the loop + driver is not already loaded when it tries to start a file-backed virtual + domain. To fix this just add "loop" in your /etc/modules file, thus + forcing it to be loaded at boot time. Copied: trunk/xen/debian/xen-utils-common.examples (from r937, trunk/xen-common/debian/xen-utils-common.examples) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.examples Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.examples) @@ -0,0 +1,2 @@ +debian/tmp/etc/xen/cpupool* +debian/tmp/etc/xen/xm* Copied and modified: trunk/xen/debian/xen-utils-common.install (from r937, trunk/xen-common/debian/xen-utils-common.install) =============================================================================--- trunk/xen-common/debian/xen-utils-common.install Wed Oct 26 23:11:27 2011 (r937, copy source) +++ trunk/xen/debian/xen-utils-common.install Tue Jan 31 13:09:30 2012 (r955) @@ -2,5 +2,5 @@ etc/xen/xl* etc/xen/xend* lib/udev/rules.d/*.rules -usr/lib/xen-common -usr/sbin +#usr/lib/xen-common +#usr/sbin Copied: trunk/xen/debian/xen-utils-common.postinst (from r937, trunk/xen-common/debian/xen-utils-common.postinst) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.postinst Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.postinst) @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e + +case "$1" in +configure) + install -d -m 0700 /var/lib/xenstored + install -d -m 2750 -g adm /var/log/xen + ;; + +abort-upgrade|abort-remove|abort-deconfigure) + ;; + +*) + echo "postinst called with unknown argument \`$1''" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 Copied: trunk/xen/debian/xen-utils-common.postrm (from r937, trunk/xen-common/debian/xen-utils-common.postrm) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.postrm Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.postrm) @@ -0,0 +1,26 @@ +#!/bin/sh + +set -e + +case "$1" in +purge) + # Remove udev rules symlink + L="/etc/udev/rules.d/z60_xen-backend.rules" + [ -L "$L" ] && rm "$L" + + XENSTORED_DIR="/var/lib/xenstored" + [ -d "${XENSTORED_DIR}" ] && rm -r "${XENSTORED_DIR}" + ;; + +remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + +*) + echo "postrm called with unknown argument \`$1''" >&2 + exit + ;; +esac + +#DEBHELPER# + +exit 0 Copied: trunk/xen/debian/xen-utils-common.preinst (from r937, trunk/xen-common/debian/xen-utils-common.preinst) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.preinst Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.preinst) @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +case "$1" in +install|upgrade) + if [ -L "/etc/udev/rules.d/z60_xen-backend.rules" ]; then + rm -f "/etc/udev/rules.d/z60_xen-backend.rules" + fi + ;; + +abort-upgrade) + ;; + +*) + echo "preinst called with unknown argument \`$1''" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 Copied: trunk/xen/debian/xen-utils-common.xen.default (from r937, trunk/xen-common/debian/xen-utils-common.xen.default) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.xen.default Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.xen.default) @@ -0,0 +1,7 @@ +# Configuration for Xen system +# ---------------------------- + +# There exists several tool stacks to configure a Xen system. +# ? +# Attention: You need to reboot after changing this! +TOOLSTACK Copied: trunk/xen/debian/xen-utils-common.xend.default (from r937, trunk/xen-common/debian/xen-utils-common.xend.default) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.xend.default Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.xend.default) @@ -0,0 +1,2 @@ +XENCONSOLED_ARGS+XENSTORED_ARGS Copied: trunk/xen/debian/xen-utils-common.xend.init (from r944, trunk/xen-common/debian/xen-utils-common.xend.init) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.xend.init Tue Jan 31 13:09:30 2012 (r955, copy of r944, trunk/xen-common/debian/xen-utils-common.xend.init) @@ -0,0 +1,178 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: xend +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: XEN control daemon +# Description: XEN control daemon +### END INIT INFO + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +DESC="Xen daemons" + +. /lib/init/vars.sh +. /lib/lsb/init-functions + +ROOT=$(/usr/lib/xen-common/bin/xen-dir 2>/dev/null) +if [ $? -ne 0 ]; then + log_warning_msg "Not running within Xen or no compatible utils" + exit 0 +fi +TOOLSTACK=$(/usr/lib/xen-common/bin/xen-toolstack 2>/dev/null) +if [ $? -ne 0 ]; then + log_warning_msg "No usable Xen toolstack selected" + exit 0 +fi + +[ -e "$ROOT"/bin/xend ] && XEND="$ROOT"/bin/xend +XENCONSOLED="$ROOT"/bin/xenconsoled +XENCONSOLED_PIDFILE="/var/run/xenconsoled.pid" +XENSTORED="$ROOT"/bin/xenstored +XENSTORED_DIR="/var/run/xenstored" +XENSTORED_PIDFILE="/var/run/xenstore.pid" + +[ -r /etc/default/xend ] && . /etc/default/xend + +modules_setup() +{ + modprobe xenfs 2>/dev/null + modprobe xen-evtchn 2>/dev/null +} + +xenfs_setup() +{ + [ -e "/proc/xen/capabilities" ] && return 0 + log_progress_msg "xenfs" + [ -d "/proc/xen" ] || return 1 + mount -t xenfs xenfs /proc/xen || return 1 + return 0 +} + +capability_check() +{ + [ -e "/proc/xen/capabilities" ] || return 1 + grep -q "control_d" /proc/xen/capabilities || return 1 + return 0 +} + +xend_start() +{ + if [ -z "$XEND" ] || [ "$(basename "$TOOLSTACK")" != xm ]; then + return 0 + fi + + log_progress_msg "xend" + $XEND status && return 1 + $XEND start || return 2 + + i=0 + while [ $i -lt 10 ]; do + $XEND status && return 0 || true + i=$(($i + 1)) + sleep 1 + done + return 2 +} + +xend_stop() +{ + [ -z "$XEND" ] && return 0 + log_progress_msg "xend" + $XEND status || return 0 + $XEND stop || return 1 +} + +xenconsoled_start() +{ + log_progress_msg "xenconsoled" + start-stop-daemon --start --quiet --pidfile "$XENCONSOLED_PIDFILE" --exec "$XENCONSOLED" --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile "$XENCONSOLED_PIDFILE" --exec "$XENCONSOLED" -- \ + $XENCONSOLED_ARGS --pid-file="$XENCONSOLED_PIDFILE" \ + || return 2 +} + +xenstored_start() +{ + log_progress_msg "xenstored" + start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" --exec "$XENSTORED" --test > /dev/null \ + || return 1 + [ -d "$XENSTORED_DIR" ] || mkdir -p "$XENSTORED_DIR" + export XENSTORED_ROOTDIR="$XENSTORED_DIR" + start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" --exec "$XENSTORED" -- \ + $XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE" \ + || return 2 +} + +case "$1" in + start) + log_daemon_msg "Starting $DESC" + modules_setup + xenfs_setup + case "$?" in + 0) ;; + *) log_end_msg 1; exit ;; + esac + capability_check + case "$?" in + 0) ;; + *) log_end_msg 255; exit ;; + esac + xenstored_start + case "$?" in + 0|1) ;; + *) log_end_msg 1; exit ;; + esac + xenconsoled_start + case "$?" in + 0|1) ;; + *) log_end_msg 1; exit ;; + esac + xend_start + case "$?" in + 0|1) ;; + *) log_end_msg 1; exit ;; + esac + log_end_msg 0 + ;; + stop) + capability_check + case "$?" in + 0) ;; + *) exit ;; + esac + log_daemon_msg "Stopping $DESC" + xend_stop + case "$?" in + 0|1) log_end_msg 0 ;; + *) log_end_msg 1 ;; + esac + ;; + restart|force-reload) + capability_check + case "$?" in + 0) ;; + *) exit ;; + esac + log_daemon_msg "Restarting $DESC" + xend_stop + case "$?" in + 0|1) + xend_start + case "$?" in + 0) log_end_msg 0 ;; + *) log_end_msg 1 ;; + esac + ;; + *) log_end_msg 1 ;; + esac + ;; + *) + echo "Usage: $0 {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +exit 0 Copied: trunk/xen/debian/xen-utils-common.xendomains.default (from r937, trunk/xen-common/debian/xen-utils-common.xendomains.default) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.xendomains.default Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.xendomains.default) @@ -0,0 +1,137 @@ +## Path: System/xen +## Description: xen domain start/stop on boot +## Type: string +## Default: +# +# The xendomains script can send SysRq requests to domains on shutdown. +# If you don''t want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks +# of the domains ("s"). +# +XENDOMAINS_SYSRQ="" + +## Type: integer +## Default: 100000 +# +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait +# (in microseconds) after each SysRq, so the domain has a chance to react. +# If you want to a quick''n''dirty shutdown via SysRq, you may want to set +# it to a relatively high value (1200000). +# +XENDOMAINS_USLEEP=100000 + +## Type: integer +## Default: 5000000 +# +# When creating a guest domain, it is sensible to allow a little time for it +# to get started before creating another domain or proceeding through the +# boot process. Without this, the booting guests will thrash the disk as they +# start up. This timeout (in microseconds) specifies the delay after guest +# domain creation. +# +XENDOMAINS_CREATE_USLEEP=5000000 + +## Type: string +## Default: "" +# +# Set this to a non-empty string if you want to migrate virtual machines +# on shutdown. The string will be passed to the xm migrate DOMID command +# as is: It should contain the target IP address of the physical machine +# to migrate to and optionally parameters like --live. Leave empty if +# you don''t want to try virtual machine relocation on shutdown. +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for +# that domain. +# +XENDOMAINS_MIGRATE="" + +## Type: string +## Default: /var/lib/xen/save +# +# Directory to save running domains to when the system (dom0) is +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE +# is set (see below). Leave empty to disable domain saving on shutdown +# (e.g. because you rather shut domains down). +# If domain saving does succeed, SHUTDOWN will not be executed. +# +XENDOMAINS_SAVE=/var/lib/xen/save + +## Type: string +## Default: "--halt --wait" +# +# If neither MIGRATE nor SAVE were enabled or if they failed, you can +# try to shut down a domain by sending it a shutdown request. To do this, +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting +# for the domain to be really down. Leave empty to skip domain shutdown. +# +XENDOMAINS_SHUTDOWN="--halt --wait" + +## Type: string +## Default: "--all --halt --wait" +# +# After we have gone over all virtual machines (resp. all automatically +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, +# migrated, saved and/or shutdown according to the settings above, we +# might want to shutdown the virtual machines that are still running +# for some reason or another. To do this, set this variable to +# "--all --halt --wait", it will be passed to xm shutdown. +# Leave it empty not to do anything special here. +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY +# is set.) +# +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" + +## Type: boolean +## Default: true +# +# This variable determines whether saved domains from XENDOMAINS_SAVE +# will be restored on system startup. +# +XENDOMAINS_RESTORE=true + +## Type: string +## Default: /etc/xen/auto +# +# This variable sets the directory where domains configurations +# are stored that should be started on system startup automatically. +# Leave empty if you don''t want to start domains automatically +# (or just don''t place any xen domain config files in that dir). +# Note that the script tries to be clever if both RESTORE and AUTO are +# set: It will first restore saved domains and then only start domains +# in AUTO which are not running yet. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO=/etc/xen/auto + +## Type: boolean +## Default: false +# +# If this variable is set to "true", only the domains started via config +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise +# all running domains will be. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO_ONLY=false + +## Type: integer +## Default: 300 +# +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, +# shutdown --all) may be executed. In the worst case, these commands may +# stall forever, which will prevent a successful shutdown of the machine. +# If this variable is non-zero, the script will set up a watchdog timer +# for every of these xm commands and time it out after the number of seconds +# specified by this variable. +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only +# zombies are still running, so you don''t need to enable this timeout just +# for the zombie case. +# The setting should be large enough to make sure that migrate/save/shutdown +# can succeed. If you do live migrations, keep in mind that live migration +# of a 1GB machine over Gigabit ethernet may actually take something like +# 100s (assuming that live migration uses 10% of the network # bandwidth). +# Depending on the virtual machine, a shutdown may also require a significant +# amount of time. So better setup this variable to a huge number and hope the +# watchdog never fires. +# +XENDOMAINS_STOP_MAXWAIT=300 + Copied: trunk/xen/debian/xen-utils-common.xendomains.init (from r937, trunk/xen-common/debian/xen-utils-common.xendomains.init) =============================================================================--- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/xen/debian/xen-utils-common.xendomains.init Tue Jan 31 13:09:30 2012 (r955, copy of r937, trunk/xen-common/debian/xen-utils-common.xendomains.init) @@ -0,0 +1,454 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: xendomains +# Required-Start: $syslog $remote_fs xend +# Should-Start: +# Required-Stop: $syslog $remote_fs xend +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start/stop secondary xen domains +# Description: Start / stop domains automatically when domain 0 +# boots / shuts down. +### END INIT INFO +# Default-Enabled: yes + +PATH=/usr/lib/xen-common/bin:/sbin:/bin:/usr/sbin:/usr/bin +VERSION=$(xen-version) +ROOT=/usr/lib/xen-$VERSION + +test "$VERSION" || exit 0 +test -e /proc/xen/privcmd || exit 0 +grep -q "control_d" /proc/xen/capabilities || exit 0 + +LOCKFILE=/var/lock/xendomains +XENDOM_CONFIG=/etc/default/xendomains + +test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing"; + if [ "$1" = "stop" ]; then exit 0; + else exit 6; fi; } + +. $XENDOM_CONFIG + +_cmd=$1 +declare -a _SMSG +if test "${_cmd}" = "status"; then + _SMSG=(running dead dead unused unknown) + _RC_UNUSED=3 +else + _SMSG=(done failed failed missed failed skipped unused failed failed) + _RC_UNUSED=6 +fi +. /lib/lsb/init-functions +echo_rc() +{ + if test ${_RC_RV} = 0; then + log_success_msg " [${_SMSG[${_RC_RV}]}] " + else + log_failure_msg " [${_SMSG[${_RC_RV}]}] " + fi +} +rc_reset() { _RC_RV=0; } +rc_failed() +{ + if test -z "$1"; then + _RC_RV=1; + elif test "$1" != "0"; then + _RC_RV=$1; + fi + return ${_RC_RV} +} +rc_check() +{ + return rc_failed $? +} +rc_status() +{ + rc_failed $? + if test "$1" = "-r"; then _RC_RV=0; shift; fi + if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi + if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi + if test "$1" = "-v"; then echo_rc; shift; fi + if test "$1" = "-r"; then _RC_RV=0; shift; fi + return ${_RC_RV} +} +rc_exit() { exit ${_RC_RV}; } + +if ! which usleep >&/dev/null +then + usleep() + { + if [ -n "$1" ] + then + sleep $(( $1 / 1000000 )) + fi + } +fi + +# Reset status of this service +rc_reset + +## +# Returns 0 (success) if the given parameter names a directory, and that +# directory is not empty. +# +contains_something() +{ + if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ] + then + return 0 + else + return 1 + fi +} + +# read name from xen config file +rdname() +{ + NM=$(xm create --quiet --dryrun --defconfig "$1" | + sed -n ''s/^.*(name \(.*\))$/\1/p'') +} + +rdnames() +{ + NAMES+ if ! contains_something "$XENDOMAINS_AUTO" + then + return + fi + for dom in $XENDOMAINS_AUTO/*; do + rdname $dom + if test -z $NAMES; then + NAMES=$NM; + else + NAMES="$NAMES|$NM" + fi + done +} + +parseln() +{ + name=`echo $1 | cut -d\ -f1` + name=${name%% *} + rest=`echo $1 | cut -d\ -f2-` + read id mem cpu vcpu state tm < <(echo "$rest") +} + +is_running() +{ + rdname $1 + RC=1 + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + case $name in + ($NM) + RC=0 + ;; + esac + done < <(xm list | tail -n +2) + return $RC +} + +start() +{ + if [ -f $LOCKFILE ]; then + echo -n "xendomains already running (lockfile exists)" + return; + fi + + if [ "$XENDOMAINS_RESTORE" = "true" ] && + contains_something "$XENDOMAINS_SAVE" + then + mkdir -p $(dirname "$LOCKFILE") + touch $LOCKFILE + echo -n "Restoring Xen domains:" + for dom in $XENDOMAINS_SAVE/*; do + echo -n " ${dom##*/}" + xm restore $dom + if [ $? -ne 0 ]; then + rc_failed $? + echo -n ''!'' + else + # mv $dom ${dom%/*}/.${dom##*/} + rm $dom + fi + done + echo . + fi + + if contains_something "$XENDOMAINS_AUTO" + then + touch $LOCKFILE + echo -n "Starting auto Xen domains:" + # We expect config scripts for auto starting domains to be in + # XENDOMAINS_AUTO - they could just be symlinks to files elsewhere + + # Create all domains with config files in XENDOMAINS_AUTO. + # TODO: We should record which domain name belongs + # so we have the option to selectively shut down / migrate later + for dom in $XENDOMAINS_AUTO/*; do + echo -n " ${dom##*/}" + if is_running $dom; then + echo -n "(skip)" + else + xm create --quiet --defconfig $dom + if [ $? -ne 0 ]; then + rc_failed $? + echo -n ''!'' + else + usleep $XENDOMAINS_CREATE_USLEEP + fi + fi + done + fi +} + +all_zombies() +{ + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + if test "$state" != "-b---d" -a "$state" != "-----d"; then + return 1; + fi + done < <(xm list | tail -n +2) + return 0 +} + +# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish; +# if it has not exited by that time kill it, so the init script will +# succeed within a finite amount of time; if $2 is nonnull, it will +# kill the command as well as soon as no domain (except for zombies) +# are left (used for shutdown --all). +watchdog_xm() +{ + if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then + exit + fi + usleep 20000 + for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do + # exit if xm save/migrate/shutdown is finished + PSAX=`ps axlw | grep "xm $1" | grep -v grep` + if test -z "$PSAX"; then exit; fi + echo -n "."; sleep 1 + # go to kill immediately if there''s only zombies left + if all_zombies && test -n "$2"; then break; fi + done + sleep 1 + read PSF PSUID PSPID PSPPID < <(echo "$PSAX") + # kill xm $1 + kill $PSPID >/dev/null 2>&1 +} + +stop() +{ + # Collect list of domains to shut down + if test "$XENDOMAINS_AUTO_ONLY" = "true"; then + rdnames + fi + echo -n "Shutting down Xen domains:" + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + echo -n " $name" + if test "$XENDOMAINS_AUTO_ONLY" = "true"; then + case $name in + ($NAMES) + # nothing + ;; + (*) + echo -n "(skip)" + continue + ;; + esac + fi + # XENDOMAINS_SYSRQ chould be something like just "s" + # or "s e i u" or even "s e s i u o" + # for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so + if test -n "$XENDOMAINS_SYSRQ"; then + for sysrq in $XENDOMAINS_SYSRQ; do + echo -n "(SR-$sysrq)" + xm sysrq $id $sysrq + if test $? -ne 0; then + rc_failed $? + echo -n ''!'' + fi + # usleep just ignores empty arg + usleep $XENDOMAINS_USLEEP + done + fi + if test "$state" = "-b---d" -o "$state" = "-----d"; then + echo -n "(zomb)" + continue + fi + if test -n "$XENDOMAINS_MIGRATE"; then + echo -n "(migr)" + watchdog_xm migrate & + WDOG_PID=$! + xm migrate $id $XENDOMAINS_MIGRATE + if test $? -ne 0; then + rc_failed $? + echo -n ''!'' + kill $WDOG_PID >/dev/null 2>&1 + else + kill $WDOG_PID >/dev/null 2>&1 + continue + fi + fi + if test -n "$XENDOMAINS_SAVE"; then + echo -n "(save)" + watchdog_xm save & + WDOG_PID=$! + mkdir -p "$XENDOMAINS_SAVE" + xm save $id $XENDOMAINS_SAVE/$name + if test $? -ne 0; then + rc_failed $? + echo -n ''!'' + kill $WDOG_PID >/dev/null 2>&1 + else + kill $WDOG_PID >/dev/null 2>&1 + continue + fi + fi + if test -n "$XENDOMAINS_SHUTDOWN"; then + # XENDOMAINS_SHUTDOWN should be "--halt --wait" + echo -n "(shut)" + watchdog_xm shutdown & + WDOG_PID=$! + xm shutdown $id $XENDOMAINS_SHUTDOWN + if test $? -ne 0; then + rc_failed $? + echo -n ''!'' + fi + kill $WDOG_PID >/dev/null 2>&1 + fi + done < <(xm list | tail -n +2) + + # NB. this shuts down ALL Xen domains (politely), not just the ones in + # AUTODIR/* + # This is because it''s easier to do ;-) but arguably if this script is run + # on system shutdown then it''s also the right thing to do. + if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then + # XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait" + echo -n " SHUTDOWN_ALL " + watchdog_xm shutdown 1 & + WDOG_PID=$! + xm shutdown $XENDOMAINS_SHUTDOWN_ALL + if test $? -ne 0; then + rc_failed $? + echo -n ''!'' + fi + kill $WDOG_PID >/dev/null 2>&1 + fi + + # Unconditionally delete lock file + rm -f $LOCKFILE +} + +check_domain_up() +{ + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + case $name in + ($1) + return 0 + ;; + esac + done < <(xm list | tail -n +2) + return 1 +} + +check_all_auto_domains_up() +{ + if ! contains_something "$XENDOMAINS_AUTO" + then + return 0 + fi + missing+ for nm in $XENDOMAINS_AUTO/*; do + rdname $nm + found=0 + if check_domain_up "$NM"; then + echo -n " $name" + else + missing="$missing $NM" + fi + done + if test -n "$missing"; then + echo -n " MISS AUTO:$missing" + return 1 + fi + return 0 +} + +check_all_saved_domains_up() +{ + if ! contains_something "$XENDOMAINS_SAVE" + then + return 0 + fi + missing=`/bin/ls $XENDOMAINS_SAVE` + echo -n " MISS SAVED: " $missing + return 1 +} + +# This does NOT necessarily restart all running domains: instead it +# stops all running domains and then boots all the domains specified in +# AUTODIR. If other domains have been started manually then they will +# not get restarted. +# Commented out to avoid confusion! + +restart() +{ + stop + start +} + +reload() +{ + restart +} + + +case "$1" in + start) + start + rc_status + if test -f $LOCKFILE; then rc_status -v; fi + ;; + + stop) + stop + rc_status -v + ;; + + restart) + restart + ;; + force-reload|reload) + reload + ;; + + status) + echo -n "Checking for xendomains:" + if test ! -f $LOCKFILE; then + rc_failed 3 + else + check_all_auto_domains_up + rc_status + check_all_saved_domains_up + rc_status + fi + rc_status -v + ;; + + *) + echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" + rc_failed 3 + rc_status -v + ;; +esac + +rc_exit