#!/bin/bash # THIS IS A DRAFT # http://refspecs.linux-foundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html [[ -z $2 ]] && echo "${0##*/} " && exit 1 conf=$1 action=$2 [[ ! -f $conf ]] && echo could not find $conf && exit 1 guest=`grep ^name $conf | cut -f2 -d'"'` if [[ $action = start ]]; then xl list $guest >/dev/null 2>&1 && exit 0 xl create $conf && echo started elif [[ $action = monitor ]]; then xl list $guest >/dev/null 2>&1 && echo OK elif [[ $action = stop ]]; then xl list $guest >/dev/null 2>&1 || exit 0 xl shutdown $guest (( maxsec = 25 )) (( sec = 0 )) while true; do sleep 1 xl list $guest >/dev/null 2>&1 && echo $guest is still up || exit 0 (( sec++ )) (( sec > maxsec )) && echo failed to shut down $guest after $maxsec seconds && exit 1 done else echo "${0##*/} " exit 1 fi