3 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Usage: start-vservers [-c <CFGDIR>] [-m <MARK>] [-j <NUM>] [--start|--stop|--status|--condrestart|--restart] [--test] [--all] [--debug] -- <name>+
20 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
21 test -e "$UTIL_VSERVER_VARS" || {
22 echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
25 . "$UTIL_VSERVER_VARS"
28 ### Some local functions
33 $"Usage: $(basename $0) [-c <CFGDIR>] [-m <MARK>] [-j <NUM] [--test]
34 [--start|--stop] [--all|--[un]marked|--running|--stopped] -- <name>+
36 Please report bugs to $PACKAGE_BUGREPORT"
41 function showVersion()
44 $"start-vserver $PACKAGE_VERSION -- starts/stops a bunch of vservers
45 This program is part of $PACKAGE_STRING
47 Copyright (C) 2004 Enrico Scholz
48 This program is free software; you may redistribute it under the terms of
49 the GNU General Public License. This program has absolutely no warranty."
53 function verifyVserver()
55 local xtra="${2:+ mentioned in '$2'}"
58 return 1;; # skip empty and comment lines
60 warning "This version of 'start-vservers' supports only short vserver names; try to remove the '$__CONFDIR' from '$1'$xtra"
64 warning "This version of 'start-vservers' supports only short vserver names; '$1'$xtra is not possible"
68 $_VSERVER_INFO -q "$__CONFDIR/$1" VDIR || {
69 warning "Vserver '$1'$xtra does not exist; skipping it..."
83 tmp=$(getopt -o c:j:m: \
84 --long debug,help,version,start,stop,test,$VS_ALLVSERVERS_ARGS \
85 -n "$0" -- "$@") || exit 1
88 declare -a tmp_vservers=()
89 declare -r TAB=$(echo -en "\t")
96 case "`basename $0`" in
97 start-*) OPTION_FLAVOR=start;;
98 stop-*) OPTION_FLAVOR=stop;;
103 getAllVserversByArg tmp_vservers "$1" || \
105 (--help) showHelp $0 ;;
106 (--version) showVersion $0 ;;
107 (-c) CONFDIR=$2; shift;;
108 (-m) OPTION_MARK=$2; OPTION_MARK_ANY=; shift;;
109 (-j) OPTION_PARALLEL=$2; shift;;
110 (--start) OPTION_FLAVOR=start;;
111 (--stop) OPTION_FLAVOR=stop;;
112 (--debug) OPTION_DEBUG=1; NOOPTION_DEBUG=; set -x;;
114 (*) echo $"$0: internal error; arg=='$1'" >&2; exit 1;;
119 test -n "$OPTION_FLAVOR" || {
120 echo "$0: unknown invocation method; aborting..." >&2
124 vservers=( "$@" "${tmp_vservers[@]}" )
126 orig_vservers=$vservers
129 while test $i -gt 0; do
131 d=$__CONFDIR/${vservers[$i]}/apps/init
133 { test -n "$OPTION_MARK_ANY"; } || \
134 { test -n "$OPTION_MARK" -a -r "$f" && grep -qx "$OPTION_MARK" "$f"; } || \
135 { test -z "$OPTION_MARK" && test ! -e "$f"; } || \
139 makedir=$($_MKTEMPDIR vserver-init.XXXXXX)
140 okfile=$($_MKTEMP vserver-init.XXXXXX)
141 passedfile=$($_MKTEMP vserver-init.XXXXXX)
142 trap "$_RM -rf $makedir $okfile $passedfile" EXIT
145 case "$OPTION_FLAVOR" in
146 start) test_cmd="${_VSERVER} --silent '\$*' status";;
147 stop) test_cmd="! ${_VSERVER} --silent '\$*' status";;
153 ${TAB}$test_cmd || { \
154 ${TAB}echo -n '.' >>$passedfile ; \
155 ${TAB}$_VSERVER --defaulttty --sync ${OPTION_DEBUG:+--debug} "\$*" ${OPTION_FLAVOR}; }
156 ${TAB}echo -n '.' >>$okfile
161 for i in "${vservers[@]}"; do
162 verifyVserver "$i" || continue
169 for i in "${vservers[@]}"; do
170 d="$__CONFDIR/$i"/apps/init
172 test -e "$d"/depends || continue
174 done | sort -u | while read vserver; do
175 verifyVserver "$vserver" || continue
176 d="$__CONFDIR/$vserver"/apps/init
178 case "$OPTION_FLAVOR" in
180 if test -e "$d"/depends; then
181 echo -ne ".$vserver.stamp:\t"
182 cat "$d"/depends | while read dep; do
183 verifyVserver "$dep" "$d"/depends || continue
184 echo -n ".$dep.stamp "
187 fi >>$makedir/Makefile
190 if test -e "$d"/depends; then
191 cat "$d"/depends | while read dep; do
192 verifyVserver "$dep" "$d"/depends || continue
193 echo -e ".$dep.stamp:\t.$vserver.stamp"
196 fi >>$makedir/Makefile
200 #cat $makedir/Makefile
201 make -k ${NOOPTION_DEBUG:+-s} ${OPTION_PARALLEL:+-j$OPTION_PARALLEL} -C $makedir
203 test -s "$passedfile" || exit 0
204 test -s "$okfile" || exit 1
205 $_CMP -s "$passedfile" "$okfile" || exit 2