4 # Copyright (C) 2003,2004,2005 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 (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
26 . "$UTIL_VSERVER_VARS"
29 ### Some local functions
34 $"Usage: $(basename $0) [-s|--sync] [-v|--verbose] [--silent] [--debug]
35 [--] <vserver> <command> <args>*
37 <vserver> is the name of a vserver.
39 Possible commands are:
40 start [--rescue [--rescue-init] <rescue-cmd> <args>*]]
41 ... starts the specified vserver
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> <command> <args*>
48 ... executes a command as the specified user in the vserver
49 exec <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, see
61 vserver ... build --help for details
62 delete ... remove a vserver
64 unify [-R] <vunify-opts>*
65 ... (de)unify the vserver with its reference vserver(s).
68 ... installs package(s) in the vserver
70 apt-get,apt-config,apt-cache <apt-opts>*
71 ... execute the apt-* command for the given vserver
73 ... execute the rpm command for the given vserver
75 pkgmgmt externalize|internalize [-y]
76 ... externalize or internalize the package-management for the
77 given vserver. 'Externalize' means that package metadata
78 and management tools (apt-get,rpm) are living in the host,
79 while 'internalize' means that data and programs from the
83 ... hashify the guest.
86 Please report bugs to $PACKAGE_BUGREPORT"
90 function showVersion()
93 $"vserver $PACKAGE_VERSION -- manages the state of vservers
94 This program is part of $PACKAGE_STRING
96 Copyright (C) 2003,2004,2005 Enrico Scholz
97 This program is free software; you may redistribute it under the terms of
98 the GNU General Public License. This program has absolutely no warranty."
104 . $__PKGLIBDIR/vserver.suexec
109 "${SELF[@]}" --sync "$vserver" stop
110 exec "${SELF[@]}" "$vserver" start
115 test -z "$OPTION_SILENT" || return 0
123 OPTIONS_ORIG=( "$@" )
124 tmp=$(getopt -o +sv --long nonamespace,--nonamespace,--insecure,defaulttty,help,debug,strace,debug-sysv,version,sync,verbose,silent -n "$0" -- "$@") || exit 1
139 (--help) showHelp $0 ;;
140 (--version) showVersion ;;
141 (--debug) OPTION_DEBUG=$1; set -x;;
142 (-v|--verbose) OPTION_VERBOSE=$1;;
143 (-s|--sync) OPTION_FORCE_SYNC=$1;;
144 (--silent) OPTION_SILENT=$1;;
145 (----nonamespace)OPTION_NONAMESPACE=$1;;
146 (--defaulttty) OPTION_DEFAULTTTY=$1;;
147 (----insecure) OPTION_INSECURE=1;;
148 (--strace) OPTION_STRACE=1;;
149 (--debug-sysv*) OPTION_DEBUG_SYSV=$1;;
151 (*) echo $"vserver: internal error; arg=='$1'" >&2; exit 1;;
156 OPTION_ALL=( $OPTION_SILENT $OPTION_VERBOSE $OPTION_DEBUG $OPTION_DEFAULTTTY )
157 SELF=( "$0" "${OPTION_ALL[@]}" )
162 test "$cmd" != build || { shift 2; exec $_VNAMESPACE --new -- \
163 "$_VSERVER_BUILD" $OPTION_DEBUG -n "$vserver" "$@"; }
168 vserver="${vserver%%/}"
170 (./*) VSERVER_DIR="`pwd`/$vserver";;
171 (/*) VSERVER_DIR="$vserver";;
172 (*) # Check if this is a context id
173 context=$(vuname --get --xid "$vserver" 2>/dev/null)
174 if test -d "$context"; then
175 VSERVER_DIR="$context"
177 VSERVER_DIR="$__CONFDIR/$vserver"
179 test ! -e "$VSERVER_DIR/legacy" || do_legacy=1
180 test -d "$VSERVER_DIR" -o ! -e "$__CONFDIR/$vserver.conf" || do_legacy=1
182 test -z "$do_legacy" || {
183 echo $"WARNING: can not find configuration, assuming legacy method" >&2
184 exec "$_VSERVER_LEGACY" "$@"
190 test -d "$VSERVER_DIR" || {
192 Can not find a vserver-setup at '$VSERVER_DIR/'.
195 * fix the spelling of the '$vserver' vserver name
196 * read 'vserver $vserver build --help' about ways to create a new vserver
197 * see 'vserver --help' for the syntax of this command
204 # Create a new namespace when starting the guest
205 test "$cmd" != start -o -n "$OPTION_NONAMESPACE" || isAvoidNamespace "$VSERVER_DIR" || \
206 exec $_VNAMESPACE --new -- $_VSERVER ----nonamespace "${OPTIONS_ORIG[@]}"
208 # Enter the namespace early so we can test for files inside the guest
209 test "$cmd" != enter -a "$cmd" != stop || \
210 test -n "$OPTION_NONAMESPACE" || isAvoidNamespace "$VSERVER_DIR" || \
211 ! isVserverRunning "$VSERVER_DIR" || \
212 exec $_VNAMESPACE --enter "$VSERVER_DIR" -- $_VSERVER ----nonamespace "${OPTIONS_ORIG[@]}"
217 . $__PKGLIBDIR/vserver.functions
221 . $__PKGLIBDIR/vserver.$cmd
228 ! isVserverRunning "$VSERVER_DIR" || restart
236 suexec 0 chkconfig "$@"
240 OPTS_VCONTEXT_ENTER=( "${OPTS_VCONTEXT_ENTER[@]}" --vlogin )
241 getEnterShell "$VSERVER_DIR"
242 suexec 0 "${ENTER_SHELL[@]}"
245 isVserverRunning "$VSERVER_DIR"
250 exec $_VUNIFY "$@" "$vserver"
255 exec $_VHASHIFY "$@" "$vserver"
260 exec $_VPKG "$vserver" "$@"
266 exec $_VNAMESPACE --new -- $_PKGMGMT ${op:+--$op} "$@" -- "$vserver"
269 (apt-get|apt-config|apt-cache)
272 exec $_VAPT_GET "$VSERVER_DIR" -- "$@"
277 exec $_VRPM "$VSERVER_DIR" -- "$@"
281 if getVserverStatus "$VSERVER_DIR" ctx procnum; then
282 msg $"Vserver '$vserver' is running at context '$ctx'"
284 if test "$2" = status; then
285 msg $"Number of processes: " $procnum
286 msg $"Uptime: " $("$_FILETIME" "$VSERVER_DIR/run")
290 msg $"Vserver '$vserver' is stopped"
295 echo $"Usage: $0 <vserver> {start|stop|suexec|restart|condrestart|exec|enter|chkconfig|running|status|delete}" >&2