7
# xendomains This required variable is a whitespace-separated
8
# list of domains, e.g., xendomains="dom1 dom2 dom3".
10
# xendomains_config This optional variable is a format string that
11
# represents the path to the configuration file for
12
# each domain. "%s" is substituted with the name of
13
# the domain. The default is "@PKG_SYSCONFDIR@/%s".
15
# xendomains_prehook This optional variable is a format string that
16
# represents the command to run, if it exists, before
17
# starting each domain. "%s" is substituted with the
18
# name of the domain. The default is
19
# "@PKG_SYSCONFDIR@/%s-pre".
21
# xendomains_posthook This optional variable is a format string that
22
# represents the command to run, if it exists, after
23
# stopping each domain. "%s" is substituted with the
24
# name of the domain. The default is
25
# "@PKG_SYSCONFDIR@/%s-post".
31
. "${DIR}/xen-hotplugpath.sh"
33
LD_LIBRARY_PATH="${LIBDIR}"
34
export LD_LIBRARY_PATH
37
ctl_command="${SBINDIR}/xl"
38
start_cmd="xendomains_start"
39
stop_cmd="xendomains_stop"
40
list_cmd="xendomains_list"
42
required_files="/kern/xen/privcmd"
46
[ -n "$xendomains" ] || return
48
echo "Starting xen domains."
49
for domain in $xendomains; do
54
# Start off by running the pre-hook script if it's present.
55
if [ -n "${xendomains_prehook}" ]; then
56
cmdline=`printf "${xendomains_prehook}" $domain`
58
if [ -x "$cmd" ]; then
59
$cmdline || echo "Pre-hook \`\`$cmdline'' failed... skipping $domain."
64
# Ask xend to create the domain.
65
if [ -n "${xendomains_config}" ]; then
66
file=`printf "${xendomains_config}" $domain`
67
if [ -f "$file" ]; then
68
${ctl_command} create "$file"
75
# Output a whitespace-separated list of live guest domains.
76
${ctl_command} list | awk '
78
($5 !~ /s/) { s = s " " $1 }
79
END { sub(" *", "", s); print s }'
84
# Determine an appropriate timeout waiting for all domains to
85
# stop -- always wait at least 60s, and add 5s per active domain.
87
numdomains=$(xendomains_list | awk '{ print NF }')
88
[ $numdomains -gt 0 ] || return
89
timeout=$((60 + numdomains * 5))
91
# Ask xend to stop every domain, and poll xend every 10s up to the
92
# timeout period to check if all the domains are stopped. We
93
# consider a domain in the "s" (shutdown) state to be stopped.
95
echo "Stopping xen domains."
96
for domain in $(xendomains_list); do
97
${ctl_command} shutdown --halt $domain
99
while [ $timeout -gt 0 ]; do
100
livedomains=$(xendomains_list)
101
[ -n "$livedomains" ] || break
102
timeout=$((timeout - 10))
105
livedomains=$(xendomains_list)
106
if [ -n "$livedomains" ]; then
107
echo "Failed to stop: $livedomains"
109
echo "All domains stopped."
112
# Finish off by running the post-hook script if it's present.
113
for domain in $xendomains; do
117
if [ -n "${xendomains_posthook}" ]; then
118
cmdline=`printf "${xendomains_posthook}" $domain`
120
if [ -x "$cmd" ]; then
121
$cmdline || echo "Post-hook \`\`$cmdline'' failed."
129
: ${xendomains_config="${XEN_CONFIG_DIR}/%s"}
130
: ${xendomains_prehook="${XEN_CONFIG_DIR}/%s-pre"}
131
: ${xendomains_posthook="${XEN_CONFIG_DIR}/%s-post"}