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:=$(dirname $0)/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) [--] <vserver> <command> <args>*
36 <vserver> is the name of a vserver.
38 Possible commands are:
39 start ... starts the specified vserver
40 stop ... stops the specified vserver
41 restart ... restarts the specified vserver; this is the subsequent
42 execution of a synchronized 'stop' and a 'start'
43 condrestart ... restarts the vserver when it is running already
44 suexec <user> <shell-command> <args*>
45 ... executes a command as the specified user in the vserver
46 exec <shell-command> <args*>
47 ... executes a command as root in the vserver
48 enter ... executes the configured shell in the vserver
49 chkconfig <chkconfig-options*>
50 ... modifies the init-system; currently, only Red Hat's
51 chkconfig is supported
52 running ... succeeds iff the vserver is running
53 status ... gives out some human readable status information about
54 the vserver, and succeeds iff the vserver is running
57 ... builds a new vserver from scratch
59 Please report bugs to $PACKAGE_BUGREPORT"
63 function showVersion()
66 $"vserver $PACKAGE_VERSION -- manages the state of vservers
67 This program is part of $PACKAGE_STRING
69 Copyright (C) 2003 Enrico Scholz
70 This program is free software; you may redistribute it under the terms of
71 the GNU General Public License. This program has absolutely no warranty."
80 tmp=$(getopt -o + --long help,version -n "$0" -- "$@") || exit 1
85 --help) showHelp $0 ;;
86 --version) showVersion ;;
88 *) echo $"vserver: internal error; arg=='$1'"; exit 1;;
92 test "$2" != build || { shift; exec "$_VSERVER_BUILD" "$@"; }
100 ./*) VSERVER_DIR=`pwd`/$vserver;;
101 /*) VSERVER_DIR=$vserver;;
102 *) VSERVER_DIR=$CONFDIR/$vserver
107 if test "$allow_legacy"; then
109 test ! -e "$VSERVER_DIR/legacy" || do_legacy=1
110 test -d "$VSERVER_DIR" -o ! -e "$CONFDIR/$vserver.conf" || do_legacy=1
112 test -z "$do_legacy" || {
113 echo $"WARNING: can not find configuration, assuming legacy method"
114 exec "$_VSERVER_LEGACY" "$@"
118 test -d "$VSERVER_DIR" || {
119 echo "Can not find vserver-setup"
123 if test -e "$VSERVER_DIR"/name; then
124 read VSERVER_NAME <"$VSERVER_DIR"/name
126 VSERVER_NAME=$(basename "$VSERVER_DIR")
129 . $PKGLIBDIR/vserver.functions
133 . $PKGLIBDIR/vserver.$cmd
140 test ! isVserverRunning "$VSERVER_DIR" || exec "$0" "$1" restart
144 exec "$0" "$vserver" suexec root "$@"
148 exec "$0" "$vserver" suexec root chkconfig "$@"
151 getEnterShell "$VSERVER_DIR"
152 exec "$0" "$1" suexec root "${ENTER_SHELL[@]}"
155 isVserverRunning "$VSERVER_DIR"
158 if getVserverStatus "$VSERVER_DIR" ctx procnum; then
159 echo $"Vserver '$1' is running at context '$ctx'"
161 if test "$2" = status; then
162 echo $"Number of processes:" $procnum
164 "$_FILETIME" "$VSERVER_DIR/run"
168 echo $"Vserver '$1' is not running"
173 echo $"Usage: $0 {start|stop|suexec|restart|condrestart|exec|enter|chkconfig|running|status}"