diff options
author | jlam <jlam@pkgsrc.org> | 2005-11-08 00:47:35 +0000 |
---|---|---|
committer | jlam <jlam@pkgsrc.org> | 2005-11-08 00:47:35 +0000 |
commit | d80d036939ee0713a89543555c127cc626be75d7 (patch) | |
tree | e6e04de367794877e2fbe49f8f43f179c18ff6e1 /sysutils/xentools20/files/xendomains.sh | |
parent | 1dc70c17c247b539769e2a147445b45f34f3b72a (diff) | |
download | pkgsrc-d80d036939ee0713a89543555c127cc626be75d7.tar.gz |
* Add a MESSAGE file with helpful information for NetBSD domain0
installations.
* Modify the package to not install all of the configuration files with
the execute bit set -- only install the helper scripts that way.
* Update the block-file-nbsd script to not blindly try to configure (and
often fail to configure) every vnd(4) device until it finds one that
works. We now just determine what the next free vnd(4) device is and
configure it directly.
* Add a netbsd-nbsd script that avoids trying to do all the Linux-specific
that just filled the log files with garbage on NetBSD.
* Update the vif-bridge-nbsd script to check that the bridge device is
configured before using it.
* Add clear comments at the top of scripts that can be customized so that
the user has enough information to know how to do the customization.
* Add a xendomains rc.d script that can be used to start and stop guest
domains at system boot- or shutdown-time.
Bump the PKGREVISION to 5.
Diffstat (limited to 'sysutils/xentools20/files/xendomains.sh')
-rw-r--r-- | sysutils/xentools20/files/xendomains.sh | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/sysutils/xentools20/files/xendomains.sh b/sysutils/xentools20/files/xendomains.sh new file mode 100644 index 00000000000..d395c4e841b --- /dev/null +++ b/sysutils/xentools20/files/xendomains.sh @@ -0,0 +1,128 @@ +#!@RCD_SCRIPTS_SHELL@ +# +# $NetBSD: xendomains.sh,v 1.1 2005/11/08 00:47:35 jlam Exp $ +# +# PROVIDE: xendomains +# REQUIRE: xend +# KEYWORD: shutdown +# +# xendomains This required variable is a whitespace-separated +# list of domains, e.g., xendomains="dom1 dom2 dom3". +# +# xendomains_config This optional variable is a format string that +# represents the path to the configuration file for +# each domain. "%s" is substituted with the name of +# the domain. The default is "@PKG_SYSCONFDIR@/%s". +# +# xendomains_prehook This optional variable is a format string that +# represents the command to run, if it exists, before +# starting each domain. "%s" is substituted with the +# name of the domain. The default is +# "@PKG_SYSCONFDIR@/%s-pre". +# +# xendomains_posthook This optional variable is a format string that +# represents the command to run, if it exists, after +# stopping each domain. "%s" is substituted with the +# name of the domain. The default is +# "@PKG_SYSCONFDIR@/%s-post". +# + +. /etc/rc.subr + +name="xendomains" +ctl_command="@PREFIX@/sbin/xm" +start_cmd="xendomains_start" +stop_cmd="xendomains_stop" +list_cmd="xendomains_list" +extra_commands="list" + +xendomains_start() +{ + [ -n "$xendomains" ] || return + + echo "Starting xen domains." + for domain in $xendomains; do + case "$domain" in + "") continue ;; + esac + + # Start off by running the pre-hook script if it's present. + if [ -n "${xendomains_prehook}" ]; then + cmdline=`printf "${xendomains_prehook}" $domain` + cmd="${cmdline%% *}" + if [ -x "$cmd" ]; then + $cmdline || echo "Pre-hook \`\`$cmdline'' failed... skipping $domain." + continue + fi + fi + + # Ask xend to create the domain. + if [ -n "${xendomains_config}" ]; then + file=`printf "${xendomains_config}" $domain` + if [ -f "$file" ]; then + ${ctl_command} create "$file" + fi + fi + done +} + +xendomains_list() { + # Output a whitespace-separated list of live guest domains. + ${ctl_command} list | awk ' + (FNR <= 2) { next } + ($5 !~ /s/) { s = s " " $1 } + END { sub(" *", "", s); print s }' +} + +xendomains_stop() +{ + # Determine an appropriate timeout waiting for all domains to + # stop -- always wait at least 60s, and add 5s per active domain. + # + numdomains=$(xendomains_list | awk '{ print NF }') + [ $numdomains -gt 0 ] || return + timeout=$((60 + numdomains * 5)) + + # Ask xend to stop every domain, and poll xend every 10s up to the + # timeout period to check if all the domains are stopped. We + # consider a domain in the "s" (shutdown) state to be stopped. + # + echo "Stopping xen domains." + for domain in $(xendomains_list); do + ${ctl_command} shutdown --halt $domain + done + while [ $timeout -gt 0 ]; do + livedomains=$(xendomains_list) + [ -n "$livedomains" ] || break + timeout=$((timeout - 10)) + sleep 10 + done + livedomains=$(xendomains_list) + if [ -n "$livedomains" ]; then + echo "Failed to stop: $livedomains" + else + echo "All domains stopped." + fi + + # Finish off by running the post-hook script if it's present. + for domain in $xendomains; do + case "$domain" in + "") continue ;; + esac + if [ -n "${xendomains_posthook}" ]; then + cmdline=`printf "${xendomains_posthook}" $domain` + cmd="${cmdline%% *}" + if [ -x "$cmd" ]; then + $cmdline || echo "Post-hook \`\`$cmdline'' failed." + fi + fi + done +} + +load_rc_config $name + +: ${xendomains_config="@PKG_SYSCONFDIR@/%s"} +: ${xendomains_prehook="@PKG_SYSCONFDIR@/%s-pre"} +: ${xendomains_posthook="@PKG_SYSCONFDIR@/%s-post"} + +run_rc_command "$1" |