4 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
22 test -e "$UTIL_VSERVER_VARS" || {
23 echo "Can not find util-vserver installation; aborting..."
26 . "$UTIL_VSERVER_VARS"
29 ### Some local functions
34 $"Usage: $(basename $0) [-s|--sync] [-v|--verbose] [--silent]
35 [--] <vserver> <command> <args>*
37 <vserver> is the name of a vserver.
39 Possible commands are:
40 start [--nodeps] <start-vservers-opts>*
41 ... starts the specified vserver
42 stop [--nodeps] <start-vservers-opts>*
43 ... stops the specified vserver
44 restart ... restarts the specified vserver; this is the subsequent
45 execution of a synchronized 'stop' and a 'start'
46 condrestart ... restarts the vserver when it is running already
47 suexec <user> <shell-command> <args*>
48 ... executes a command as the specified user in the vserver
49 exec <shell-command> <args*>
50 ... executes a command as root in the vserver
51 enter ... executes the configured shell in the vserver
52 chkconfig <chkconfig-options*>
53 ... modifies the init-system; currently, only Red Hat's
54 chkconfig is supported
55 running ... succeeds iff the vserver is running
56 status ... gives out some human readable status information about
57 the vserver, and succeeds iff the vserver is running
60 ... builds a new vserver from scratch
66 ... installs package(s) in the vserver
68 apt-get,apt-config,apt-cache <apt-opts>*
69 ... execute the apt-* command for the given vserver
71 ... execute the rpm command for the given vserver
73 pkgmgmt externalize|internalize [-y]
74 ... externalize or internalize the package-management for the
75 given vserver. 'Externalize' means that package metadata
76 and management tools (apt-get,rpm) are living in the host,
77 while 'internalize' means that data and programs from the
81 ... unify the vserver with its reference vserver(s).
84 Please report bugs to $PACKAGE_BUGREPORT"
88 function showVersion()
91 $"vserver $PACKAGE_VERSION -- manages the state of vservers
92 This program is part of $PACKAGE_STRING
94 Copyright (C) 2003 Enrico Scholz
95 This program is free software; you may redistribute it under the terms of
96 the GNU General Public License. This program has absolutely no warranty."
102 . $PKGLIBDIR/vserver.suexec
107 "${SELF[@]}" --sync "$vserver" stop
108 exec "${SELF[@]}" "$vserver" start
115 OPTIONS_ORIG=( "$@" )
116 tmp=$(getopt -o +sv --long nonamespace,--nonamespace,help,debug,version,sync,verbose,silent -n "$0" -- "$@") || exit 1
127 --help) showHelp $0 ;;
128 --version) showVersion ;;
129 --debug) OPTION_DEBUG=$1; set -x;;
130 -v|--verbose) OPTION_VERBOSE=$1;;
131 -s|--sync) OPTION_FORCE_SYNC=$1;;
132 --silent) OPTION_SILENT=$1;;
133 ----nonamespace)OPTION_NONAMESPACE=$1;;
135 *) echo $"vserver: internal error; arg=='$1'"; exit 1;;
140 OPTION_ALL=( $OPTION_SILENT $OPTION_VERBOSE $OPTION_DEBUG )
141 SELF=( "$0" "${OPTION_ALL[@]}" )
146 test "$cmd" != build || { shift 2; exec "$_VSERVER_BUILD" -n "$vserver" "$@"; }
152 ./*) VSERVER_DIR=`pwd`/$vserver;;
153 /*) VSERVER_DIR=$vserver;;
154 *) VSERVER_DIR=$CONFDIR/$vserver
159 if test "$allow_legacy"; then
161 test ! -e "$VSERVER_DIR/legacy" || do_legacy=1
162 test -d "$VSERVER_DIR" -o ! -e "$CONFDIR/$vserver.conf" || do_legacy=1
164 test -z "$do_legacy" || {
165 echo $"WARNING: can not find configuration, assuming legacy method"
166 exec "$_VSERVER_LEGACY" "$@"
170 test -d "$VSERVER_DIR" || {
171 echo "Can not find vserver-setup"
175 if test -e "$VSERVER_DIR"/name; then
176 read VSERVER_NAME <"$VSERVER_DIR"/name
178 VSERVER_NAME=$(basename "$VSERVER_DIR")
181 test "$2" != start -o "$OPTION_NONAMESPACE" || isAvoidNamespace "$VSERVER_DIR" || \
182 exec $_NEW_NAMESPACE "$0" ----nonamespace "${OPTIONS_ORIG[@]}"
184 . $PKGLIBDIR/vserver.functions
188 . $PKGLIBDIR/vserver.$cmd
195 test ! isVserverRunning "$VSERVER_DIR" || restart
203 suexec root chkconfig "$@"
206 getEnterShell "$VSERVER_DIR"
207 suexec root "${ENTER_SHELL[@]}"
210 isVserverRunning "$VSERVER_DIR"
215 exec $_VUNIFY "$@" "$vserver"
220 exec $_VPKG "$vserver" "$@"
223 apt-get|apt-config|apt-cache)
226 exec $_VAPT_GET -- "$@"
233 if getVserverStatus "$VSERVER_DIR" ctx procnum; then
234 echo $"Vserver '$vserver' is running at context '$ctx'"
236 if test "$2" = status; then
237 echo $"Number of processes:" $procnum
239 "$_FILETIME" "$VSERVER_DIR/run"
243 echo $"Vserver '$vserver' is not running"
248 echo $"Usage: $0 {start|stop|suexec|restart|condrestart|exec|enter|chkconfig|running|status}"