aboutsummaryrefslogtreecommitdiffstats
path: root/tools/examples
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-10-29 09:51:35 +0100
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-10-29 09:51:35 +0100
commit1464591d5ff73c5c8a983851be6263724a63314b (patch)
tree6ccff4fc606196f778f017629e2de80561e1119c /tools/examples
parent6a106a03b089d9f6153d29188497adc150cb2eeb (diff)
parentadeed21529928c872b8379714a976c2380d176eb (diff)
downloadxen-1464591d5ff73c5c8a983851be6263724a63314b.tar.gz
xen-1464591d5ff73c5c8a983851be6263724a63314b.tar.bz2
xen-1464591d5ff73c5c8a983851be6263724a63314b.zip
merge
Diffstat (limited to 'tools/examples')
-rw-r--r--tools/examples/Makefile6
-rw-r--r--tools/examples/block16
-rw-r--r--tools/examples/block-common.sh51
-rwxr-xr-xtools/examples/block-enbd14
-rw-r--r--tools/examples/block-nbd27
-rw-r--r--tools/examples/init.d/sysconfig.xendomains126
-rw-r--r--[-rwxr-xr-x]tools/examples/init.d/xendomains480
-rwxr-xr-xtools/examples/network-bridge4
-rw-r--r--tools/examples/xen-hotplug-common.sh18
-rw-r--r--tools/examples/xen-network-common.sh38
-rw-r--r--tools/examples/xmexample.nbd23
11 files changed, 697 insertions, 106 deletions
diff --git a/tools/examples/Makefile b/tools/examples/Makefile
index 2431eb0bf6..91cea9b5de 100644
--- a/tools/examples/Makefile
+++ b/tools/examples/Makefile
@@ -9,6 +9,7 @@ INSTALL_DATA = $(INSTALL) -m0644
# Init scripts.
XEND_INITD = init.d/xend
XENDOMAINS_INITD = init.d/xendomains
+XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
# Xen configuration dir and configs to go there.
XEN_CONFIG_DIR = /etc/xen
@@ -24,8 +25,9 @@ XEN_SCRIPTS = network-bridge vif-bridge
XEN_SCRIPTS += network-route vif-route
XEN_SCRIPTS += network-nat vif-nat
XEN_SCRIPTS += block
-XEN_SCRIPTS += block-enbd
+XEN_SCRIPTS += block-enbd block-nbd
XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
+XEN_SCRIPTS += block-common.sh
XEN_HOTPLUG_DIR = /etc/hotplug
XEN_HOTPLUG_SCRIPTS = xen-backend.agent
@@ -52,8 +54,10 @@ install: all install-initd install-configs install-scripts $(HOTPLUGS)
install-initd:
[ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d
+ [ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) $(DESTDIR)/etc/sysconfig
$(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d
$(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d
+ $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xendomains
install-configs: $(XEN_CONFIGS)
[ -d $(DESTDIR)$(XEN_CONFIG_DIR) ] || \
diff --git a/tools/examples/block b/tools/examples/block
index 2e383bb3a6..c5b6b6c215 100644
--- a/tools/examples/block
+++ b/tools/examples/block
@@ -1,7 +1,7 @@
#!/bin/sh
dir=$(dirname "$0")
-. "$dir/xen-hotplug-common.sh"
+. "$dir/block-common.sh"
expand_dev() {
local dev
@@ -16,21 +16,9 @@ expand_dev() {
echo -n $dev
}
-write_dev() {
- local major
- local minor
- local pdev
-
- major=$(stat -L -c %t "$1")
- minor=$(stat -L -c %T "$1")
- pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
- xenstore_write "$XENBUS_PATH"/physical-device $pdev \
- "$XENBUS_PATH"/node $1
-}
-
t=$(xenstore_read "$XENBUS_PATH"/type || true)
-case $1 in
+case "$command" in
bind)
p=$(xenstore_read "$XENBUS_PATH"/params)
case $t in
diff --git a/tools/examples/block-common.sh b/tools/examples/block-common.sh
new file mode 100644
index 0000000000..1d20550a9d
--- /dev/null
+++ b/tools/examples/block-common.sh
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2005 XenSource Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+
+dir=$(dirname "$0")
+. "$dir/xen-hotplug-common.sh"
+
+command="$1"
+
+if [ "$command" != "bind" ] && [ "$command" != "unbind" ]
+then
+ log err "Invalid command: $command"
+ exit 1
+fi
+
+
+XENBUS_PATH="${XENBUS_PATH:?}"
+
+
+##
+# Write physical-device = 0xMMmm and node = device to the store, where MM
+# and mm are the major and minor numbers of device.
+#
+# @param device The device from which major and minor numbers are read, which
+# will be written into the store.
+#
+write_dev() {
+ local major
+ local minor
+ local pdev
+
+ major=$(stat -L -c %t "$1")
+ minor=$(stat -L -c %T "$1")
+ pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor")
+ xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \
+ "$XENBUS_PATH"/node "$1"
+}
diff --git a/tools/examples/block-enbd b/tools/examples/block-enbd
index c86068d817..c58adb595d 100755
--- a/tools/examples/block-enbd
+++ b/tools/examples/block-enbd
@@ -2,25 +2,19 @@
# Usage: block-enbd [bind server ctl_port |unbind node]
#
-# The file argument to the bind command is the file we are to bind to a
-# loop device.
-#
# The node argument to unbind is the name of the device node we are to
# unbind.
#
# This assumes you're running a correctly configured server at the other end!
-set -e
+dir=$(dirname "$0")
+. "$dir/block-common.sh"
-case $1 in
+case "$command" in
bind)
for dev in /dev/nd*; do
if nbd-client $2:$3 $dev; then
- major=$(stat -L -c %t "$dev")
- minor=$(stat -L -c %T "$dev")
- pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
- xenstore-write "$XENBUS_PATH"/physical-device $pdev \
- "$XENBUS_PATH"/node $dev
+ write_dev $dev
exit 0
fi
done
diff --git a/tools/examples/block-nbd b/tools/examples/block-nbd
new file mode 100644
index 0000000000..142a403c0f
--- /dev/null
+++ b/tools/examples/block-nbd
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Usage: block-nbd [bind server ctl_port |unbind node]
+#
+# The node argument to unbind is the name of the device node we are to
+# unbind.
+#
+# This assumes you're running a correctly configured server at the other end!
+
+dir=$(dirname "$0")
+. "$dir/block-common.sh"
+
+case "$command" in
+ bind)
+ for dev in /dev/nbd*; do
+ if nbd-client $2 $3 $dev; then
+ write_dev $dev
+ exit 0
+ fi
+ done
+ exit 1
+ ;;
+ unbind)
+ nbd-client -d $2
+ exit 0
+ ;;
+esac
diff --git a/tools/examples/init.d/sysconfig.xendomains b/tools/examples/init.d/sysconfig.xendomains
new file mode 100644
index 0000000000..fa95c145cc
--- /dev/null
+++ b/tools/examples/init.d/sysconfig.xendomains
@@ -0,0 +1,126 @@
+## 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: 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
+
diff --git a/tools/examples/init.d/xendomains b/tools/examples/init.d/xendomains
index ac2b273fd7..4d7db36295 100755..100644
--- a/tools/examples/init.d/xendomains
+++ b/tools/examples/init.d/xendomains
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# /etc/init.d/xendomains
# Start / stop domains automatically when domain 0 boots / shuts down.
@@ -22,101 +22,418 @@
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
+# Default-Enabled: yes
# Short-Description: Start/stop secondary xen domains
# Description: Start / stop domains automatically when domain 0
# boots / shuts down.
### END INIT INFO
+# 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
exit 0
fi
-RETVAL=0
-
-INITD=/etc/init.d
-
-AUTODIR=/etc/xen/auto
LOCKFILE=/var/lock/subsys/xendomains
+XENDOM_CONFIG=/etc/sysconfig/xendomains
-if [ -e /lib/lsb ]; then
- # assume an LSB-compliant distro (Debian with LSB package,
- # recent-enough SuSE, others...)
+test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
+ if [ "$1" = "stop" ]; then exit 0;
+ else exit 6; fi; }
- . /lib/lsb/init-functions # source LSB standard functions
+. $XENDOM_CONFIG
- on_fn_exit()
+# Use the SUSE rc_ init script functions;
+# emulate them on LSB, RH and other systems
+if test -e /etc/rc.status; then
+ # SUSE rc script library
+ . /etc/rc.status
+else
+ _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
+ if test -e /lib/lsb/init-functions; then
+ # LSB
+ . /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
+ }
+ elif test -e /etc/init.d/functions; then
+ # REDHAT
+ . /etc/init.d/functions
+ echo_rc()
+ {
+ #echo -n " [${_SMSG[${_RC_RV}]}] "
+ if test ${_RC_RV} = 0; then
+ success " [${_SMSG[${_RC_RV}]}] "
+ else
+ failure " [${_SMSG[${_RC_RV}]}] "
+ fi
+ }
+ else
+ # emulate it
+ echo_rc()
+ {
+ echo " [${_SMSG[${_RC_RV}]}] "
+ }
+ fi
+ rc_reset() { _RC_RV=0; }
+ rc_failed()
{
- if [ $RETVAL -eq 0 ]; then
- log_success_msg
- else
- log_failure_msg
- fi
+ if test -z "$1"; then
+ _RC_RV=1;
+ elif test "$1" != "0"; then
+ _RC_RV=$1;
+ fi
+ return ${_RC_RV}
}
-elif [ -r $INITD/functions ]; then
- # assume a Redhat-like distro
- . $INITD/functions # source Redhat functions
-
- on_fn_exit()
+ rc_check()
{
- if [ $RETVAL -eq 0 ]; then
- success
- else
- failure
- fi
-
- echo
+ 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}
}
-else
- # none of the above
- LOCKFILE=/var/lock/xendomains
-
- on_fn_exit()
+ rc_exit() { exit ${_RC_RV}; }
+ rc_active()
{
- echo
+ if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
+ if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
+ return 1
}
fi
+if ! which usleep >&/dev/null
+then
+ usleep()
+ {
+ if [ -n "$1" ]
+ then
+ sleep $(( $1 / 1000 ))
+ 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=`grep '^name *=' $1 | sed -e 's/^name *= *"\([^"]*\)".*$/\1/' -e 's/%[id]/[0-9]*/g'`
+}
+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
+}
-start() {
- if [ -f $LOCKFILE ]; then return; fi
+parseln()
+{
+ name=`echo "$1" | cut -c0-17`
+ name=${name%% *}
+ rest=`echo "$1" | cut -c18- `
+ read id mem cpu vcpu state tm < <(echo "$rest")
+}
- echo -n $"Starting auto Xen domains:"
+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 | grep -v '^Name')
+ return $RC
+}
- # We expect config scripts for auto starting domains to be in
- # AUTODIR - they could just be symlinks to files elsewhere
- if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then
+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
-
- # Create all domains with config files in AUTODIR.
- for dom in $AUTODIR/*; do
- xm create --quiet --defconfig $dom
+ echo -n "Restoring Xen domains:"
+ for dom in $XENDOMAINS_SAVE/*; do
+ echo -n " ${dom##*/}"
+ xm restore $dom
if [ $? -ne 0 ]; then
- RETVAL=$?
+ rc_failed $?
+ echo -n '!'
+ else
+ # mv $dom ${dom%/*}/.${dom##*/}
+ rm $dom
fi
done
-
fi
- on_fn_exit
+ 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 '!'
+ 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 | grep -v '^Name')
+ 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=$!
+ xm save $id $XENDOMAINS_SAVE/$name
+ if test $? -ne 0; then
+ rc_failed $?
+ echo -n '!'
+ kill $WDOG_PIG >/dev/null 2>&1
+ else
+ kill $WDOG_PIG >/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_PIG >/dev/null 2>&1
+ fi
+ done < <(xm list | grep -v '^Name')
+
# 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.
-
- echo -n $"Shutting down all Xen domains:"
+ 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
- xm shutdown --all --wait --halt
+ # Unconditionally delete lock file
+ rm -f $LOCKFILE
+}
- RETVAL=$?
+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 | grep -v "^Name")
+ return 1
+}
- [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
+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
+}
- on_fn_exit
+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
@@ -124,47 +441,56 @@ stop()
# AUTODIR. If other domains have been started manually then they will
# not get restarted.
# Commented out to avoid confusion!
-#
-#restart()
-#{
-# stop
-# start
-#}
-# same as restart for now - commented out to avoid confusion
-#reload()
-#{
-# restart
-#}
+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
;;
-# The following are commented out to disable them by default to avoid confusion
-# - see the notes above
-#
-# restart)
-# restart
-# ;;
-#
-# reload)
-# reload
-# ;;
+ restart)
+ restart
+ ;;
+ reload)
+ reload
+ ;;
status)
- xm list
+ 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|status}"
+ echo "Usage: $0 {start|stop|restart|reload|status}"
+ rc_failed 3
+ rc_status -v
;;
esac
-exit $RETVAL
+rc_exit
diff --git a/tools/examples/network-bridge b/tools/examples/network-bridge
index c9d00b8e81..e9a75ea749 100755
--- a/tools/examples/network-bridge
+++ b/tools/examples/network-bridge
@@ -208,7 +208,7 @@ op_start () {
if ip link show ${vdev} 2>/dev/null >/dev/null; then
mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
- eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- ${netdev}`
+ preiftransfer ${netdev}
transfer_addrs ${netdev} ${vdev}
if ! ifdown ${netdev}; then
# if ifup didn't work, see if we have an ip= on cmd line
@@ -231,7 +231,7 @@ op_start () {
ip link set ${bridge} up
ip link set ${vif0} up
ip link set ${pdev} up
- if ! ifup ${HWD_CONFIG_0} ${netdev} ; then
+ if ! ifup ${netdev} ; then
if [ ${kip} ] ; then
# use the addresses we grocked from /proc/cmdline
if [ -z "${kmask}" ]; then
diff --git a/tools/examples/xen-hotplug-common.sh b/tools/examples/xen-hotplug-common.sh
index c25f493551..5beb12d60a 100644
--- a/tools/examples/xen-hotplug-common.sh
+++ b/tools/examples/xen-hotplug-common.sh
@@ -1,3 +1,21 @@
+#
+# Copyright (c) 2005 XenSource Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+
set -e
export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
diff --git a/tools/examples/xen-network-common.sh b/tools/examples/xen-network-common.sh
index d4af3990ca..c2fc311fac 100644
--- a/tools/examples/xen-network-common.sh
+++ b/tools/examples/xen-network-common.sh
@@ -16,11 +16,40 @@
#
-# Gentoo doesn't have ifup/ifdown: define appropriate alternatives
-if ! which ifup >&/dev/null
+# On SuSE it is necessary to run a command before transfering addresses and
+# routes from the physical interface to the virtual. This command creates a
+# variable $HWD_CONFIG_0 that specifies the appropriate configuration for
+# ifup.
+
+# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives.
+
+# Other platforms just use ifup / ifdown directly.
+
+##
+# preiftransfer
+#
+# @param $1 The current name for the physical device, which is also the name
+# that the virtual device will take once the physical device has
+# been renamed.
+
+if [ -e /etc/SuSE-release ]
+then
+ preiftransfer()
+ {
+ eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- $1`
+ }
+ ifup()
+ {
+ /sbin/ifup ${HWD_CONFIG_0} $1
+ }
+elif ! which ifup >&/dev/null
then
if [ -e /etc/conf.d/net ]
then
+ preiftransfer()
+ {
+ true
+ }
ifup()
{
/etc/init.d/net.$1 start
@@ -34,4 +63,9 @@ then
"You don't have ifup and don't seem to be running Gentoo either!"
exit 1
fi
+else
+ preiftransfer()
+ {
+ true
+ }
fi
diff --git a/tools/examples/xmexample.nbd b/tools/examples/xmexample.nbd
new file mode 100644
index 0000000000..274be6eb06
--- /dev/null
+++ b/tools/examples/xmexample.nbd
@@ -0,0 +1,23 @@
+# -*- mode: python; -*-
+#
+# xm create configuration example.
+#
+# This configuration is appropriate for using Network Block Device (NBD)
+# filesystems.
+#
+# Each of these parameters will need changing to match your setup.
+#
+
+kernel = "/boot/vmlinuz-2.6.13-15b-xen"
+ramdisk = "/boot/initrd-2.6.13-15b-xen"
+memory = 128
+name = "nbd4"
+nics=1
+# Please change MAC
+vif = [ 'mac=aa:cc:10:10:00:a0, bridge=xenbr0' ]
+# Please change PORT
+disk = [ 'nbd:134.100.233.115 20004,hda1,w' ]
+dhcp = "dhcp"
+hostname= "nbd4"
+root = "/dev/hda1 ro"
+extra = "3"