#!/bin/sh #----------------------------------------------------------------------------- # /var/install/bin/xen-maintain-domain # # Creation: 2008-08-05 rg # Last Update: $Id$ # # Copyright (c) 2007-2012 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #----------------------------------------------------------------------------- . /var/install/include/xenlib #exec 2> /tmp/xen-maintain-domain-trace$$.log #set -x # $1 must be one of these arguments: check_modules, manage_domain, delete_domain # $2 must be the name of the domain: name="$2" # $3 can be "xendIsRuning" # clrhome clrhome echo xendIsRuning=false [ "$3" = xendIsRuning ] && xendIsRuning=true || { mecho --info "Checking if xend is running$_RESET .." /etc/init.d/xen status >/dev/null 2>&1 && xendIsRuning=true } [ "$1" = check_modules ] && { $xendIsRuning && checkIfVMIsUp "$name" ${isUp:-false} && mecho --warn "Domain $name is running.\nUpdating Kernel modules not possible." || "$1" "$name" force } [ "$1" = manage_domain ] && { $xendIsRuning || /etc/init.d/xen startxend while : do clrhome bootOrder=`ls ${domUConfigfile}_??_$name | sed -e 's#^'$domUConfigfile'_##' -e 's#_'$name'$##'` checkIfVMIsUp "$name" echo mecho --info "Management for Xen domain $_BOLD$name" echo mecho -n "Status: " ${isUp:-false} && mecho --info "Domain is running" || mecho --warn "Domain is not running" isBuilt=false if isfli4l "$name" then mecho -n "Buildstatus: " [ -f "$fli4lPath/config.$name/build/rc.cfg" ] && { isBuilt=true mecho "Domain is built!\n\n" } || mecho --warn "Domain is not built!\nYou have to run mkfli4l first\n\n" mecho "fli4l configuration file(s):\n" techo --begin '5r 2 30' techo --info --row No. "" Filename idx=1 for conffile in $fli4lPath/config.$name/*.$extension do techo --row "$idx " - "`basename $conffile`" eval 'conf_'$idx'='$conffile idx=`expr $idx + 1` done idx=`expr $idx - 1` techo --end fi mecho -n "Boot-Order: " mecho --info "$bootOrder" echo echo "Please enter command:" if $isBuilt || ! isfli4l $name then ${isUp:-false} && { mecho " [${_INFO}s$_RESET]hutdown," mecho " s[${_INFO}u$_RESET]spend," mecho " [${_INFO}c$_RESET]onnect," mecho " [${_INFO}k$_RESET]ill," mecho " [${_INFO}r$_RESET]eboot" mecho " [${_INFO}n$_RESET]ew boot order" } || { mecho " [${_INFO}b$_RESET]oot," mecho " b[${_INFO}o$_RESET]ot & connect," mecho " [${_INFO}n$_RESET]ew boot order" } fi if isfli4l "$name" then mecho "run [${_INFO}m$_RESET]kfli4l," echo mecho -n "Enter command or" [ $idx -eq 1 ] && mecho -n " [${_INFO}1$_RESET]" || mecho -n " [${_INFO}1-$idx$_RESET]" mecho -n " to edit configuration file, ${_INFO}ENTER$_RESET=Return: " else echo mecho -n "${_INFO}ENTER$_RESET=Return: " fi read cmd case "$cmd" in "") break ;; "m") cd "$fli4lPath" sh mkfli4l.sh config.$name && { cd $fli4lPath/config.$name/build mecho --info "You can disconnect from the virtual machine by pressing Ctrl-]" echo "(On german keyboards typically Strg-AltGr-9, PuTTY Strg-+)" ${isUp:-false} && { /var/install/bin/ask --tty --info "Reboot domain now" "y" && xm reboot $name } || { /var/install/bin/ask --tty --info "Boot & connect to Xen domain now" "y" && { /etc/init.d/xen netstatus || /etc/init.d/xen startnet # XXX: api handling registrate_domain "$name" xm start "$name" #xm create /etc/xen/xm/xm$name sleep $waitTime xm console "$name" } } } || mecho --error "The build of fli4l returned an error!" anykey ;; "n") mecho -n "Boot order (min 01 max 99) smaler numbers will boot before big numbers [$_INFO$bootOrder$_RESET]: " read order while : do case "$order" in "") order="$bootOrder" break ;; [1-9]) order="0$order" break ;; [0-9][0-9]) break ;; *) mecho --error "only numbers between 1 an 99" mecho -n "Please enter boot order [$_INFO$bootOrder$_RESET]: " read order ;; esac done remove ${domUConfigfile}_${bootOrder}_$name ln_relative -s $domUConfigfile$delimiter$name ${domUConfigfile}_${order}_$name ;; "r") ${isUp:-false} && { echo "Rebooting $name..." xm shutdown --reboot "$name" } anykey ;; "s") ${isUp:-false} && { echo "Shutting down $name..." xm shutdown "$name" } anykey ;; "u") ${isUp:-false} && { echo "Suspending domain $name..." xm suspend $name } anykey ;; "k") ${isUp:-false} && { echo "Powering off domain $name..." xm destroy "$name" } anykey ;; "b") ${isUp:-false} || { /etc/init.d/xen netstatus >/dev/null 2>&1 || /etc/init.d/xen startnet # XXX: api handling # �berpr�fen, ob f�r diese domU noch �nderungen in # das xen repository ausstehen. Ggf. �nderungen # �bernehmen [ -f /etc/xen/pending-changes/$name ] && { xm del $name >/dev/null 2>&1 registrate_domain $name >/dev/null 2>&1 remove /etc/xen/pending-changes/$name rmdir /etc/xen/pending-changes >/dev/null 2>&1 } echo "Booting $name..." # XXX: api handling xm start $name #xm create /etc/xen/xm/xm$name } anykey ;; "c") ${isUp:-false} && { mecho --info "You can disconnect from this domain by pressing Ctrl-]" xm console "$name" } ;; "o") ${isUp:-false} || { /etc/init.d/xen netstatus >/dev/null 2>&1 || /etc/init.d/xen startnet # XXX: api handling # �berpr�fen, ob f�r diese domU noch �nderungen in # das xen repository ausstehen. Ggf. �nderungen # �bernehmen [ -f /etc/xen/pending-changes/$name ] && { xm del $name >/dev/null 2>&1 registrate_domain $name >/dev/null 2>&1 remove /etc/xen/pending-changes/$name rmdir /etc/xen/pending-changes >/dev/null 2>&1 } mecho --info "You can disconnect from this virtual machine by pressing Ctrl-]" echo "(On german keyboards typically Strg-AltGr-9, PuTTY Strg-+)" anykey # XXX: api handling xm start "$name" #xm create /etc/xen/xm/xm$name xm console "$name" } anykey ;; [1-9]|[1-9][0-9]) eval 'conffile=$conf_'$cmd confbasename=`basename $conffile` eval confname="\`echo $confbasename | sed \"s#\\.${extension}##\"\`" cd $fli4lPath $EDITOR $conffile # /var/install/bin/edit-conf.cui -f -c -m \ # --config-base=config.$name \ # --check-base=check \ # --default-base=config \ # --default-ext=$extension \ # --help-base=help \ # $confname ;; esac done } [ "$1" = delete_domain ] && { $xendIsRuning && checkIfVMIsUp "$name" # clrhome deleteDomU=true ${isUp:-false} && { /var/install/bin/ask --tty --warn "${_ERROR}Domain '$name' is running.$_RESET\nDo you really want to delete this domain?" "n" && xm destroy $name || deleteDomU=false } $deleteDomU && { if [ -r "$domUConfigfile$delimiter$name" ] then . "$domUConfigfile$delimiter$name" else mecho --warn "$domUConfigfile$delimiter$name does not exist," mecho --warn "domU $name was maybe removed earlier already." mecho --warn "Leave and re-enter the domU section to see if it disapeared." exit 1 fi echo /var/install/bin/ask --tty --warn "Delete all configuration and built files of domain '$name'?" "n" && { echo mecho --warn "Deleting config files of domain $name..." # XXX: api handling xm list | grep -qs "^${name}" && xm delete $name for path in "$fli4lPath/build.$name"\ "$fli4lPath/config.$name"\ $vmConfigPath/$vmConfigPrefix$name\ ${domUConfigfile}_${bootOrder}_$name\ $domUConfigfile$delimiter$name\ ${domUConfigfile}_[0-9][0-9]_$name\ /etc/init.d/$domUConfigPrefix$delimiter$name do remove $path : mecho --warn done cd echo if [ "$IS_FLI4L" = no ] then if ls $xenImagePath/$name.* >/dev/null 2>&1 then /var/install/bin/ask --tty --warn "Delete the image files of domain '$name'?" "n" && { mecho --warn "\nDeleting image files of domain $name..." for path in $xenImagePath/$name.* do remove path true mecho --warn done } elif [ -b /dev/$volumeGroup/$name -o -b /dev/$volumeGroup/$name-swap ] then /var/install/bin/ask --tty --warn "Delete the logical volumes of domain '$name'?" "n" && { mecho --warn "\nDeleting logical volumes of domain $name..." for volume in `lvs | awk '$1 == "'$name'" || $1 == "'$name-swap'" { print $1 }'` do [ -b /dev/$volumeGroup/$volume ] && mecho --warn " -`lvremove -f /dev/$volumeGroup/$volume`" done } fi echo fi preSetup } } } #TODO: This can do annything we want: # in development: # Temporarily (loop-)mount this domain # Edit fstab and other sysfiles in this domain # Verbose Information about this domain # Change start order # Start/stop this domain # etc.. anykey #set +x