3 # Copyright (C) 2003 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.
19 lock "$__LOCKDIR"/vserver."$($_VSERVER_INFO "$VSERVER_DIR" CANONIFY)".startup
21 if isVserverRunning "$VSERVER_DIR"; then
22 warning $"vserver '$VSERVER_NAME' already running"
30 test -z "$startsync_pipe" || $_RM -f "$startsync_pipe"
31 test -z "$is_started" || { unlock; return 0; }
33 if test -n "$is_configured" -a -z "$is_executed"; then
35 An error occured while executing the vserver startup sequence; when
36 there are no other messages, it is very likely that the init-script
37 (${INITCMD_START[@]}) failed.
40 * /etc/rc.d/rc on Fedora Core 1 and RH9 fails always; the 'apt-rpm' build
41 method knows how to deal with this, but on existing installations,
42 appending 'true' to this file will help."
45 if test -n "$is_executed"; then
47 An error occured after executing the vserver startup sequence. This
48 means that some processes may exist in the created context and the
51 $_VSERVER '$VSERVER_DIR' stop
53 is recommended to fix this."
57 Failed to start vserver '$VSERVER_NAME'"
60 test -n "$OPTION_DEBUG" || exec 2>/dev/null >/dev/null
61 test -z "$is_mounted" || umountVserver "$VSERVER_DIR" || :
62 test -z "$have_interfaces" || disableInterfaces "$VSERVER_DIR" || :
76 while test "$#" -gt 0; do
78 (--rescue) INITSTYLE=rescue;;
81 The '--rescue-cmd' option is deprecated; just add the the initcmd
82 inclusive its arguments to the cmdline."
83 INITCMD_RESCUE=( $2 );
86 (--rescue-init) _IS_FAKEINIT=1;;
88 (-*) panic $"vserver ... start: unknown option '$1'";;
94 if test x"$INITSTYLE" = xrescue -a -z "$have_initcmd" -a "$#" -gt 0; then
95 INITCMD_RESCUE=( "$@" )
102 sanityCheck "$VSERVER_DIR"
104 pushd "$VSERVER_DIR" >/dev/null
105 execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" initialize
108 fsckAllFS "$VSERVER_DIR"
110 mountRootFS "$VSERVER_DIR"
111 generateOptions "$VSERVER_DIR"
113 pushd "$VSERVER_DIR" >/dev/null
114 execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" prepre-start
117 setDiskLimits "$VSERVER_DIR"
119 enableInterfaces "$VSERVER_DIR" && have_interfaces=1
121 mountVserver "$VSERVER_DIR" && is_mounted=1
122 prepareInit "$VSERVER_DIR"
123 addtoCPUSET "$VSERVER_DIR"
125 handleDeviceMap --set "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
127 pushd "$VSERVER_DIR"/vdir/ >/dev/null
128 execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" pre-start
131 test -z "$OPTION_DEFAULTTTY" || setDefaultTTY "$VSERVER_DIR"
133 pushd "$VSERVER_DIR"/vdir/ >/dev/null
135 if $_VSERVER_INFO - FEATURE migrate; then
139 $_EXEC_ULIMIT "$VSERVER_DIR"/ulimits \
140 $_VTAG --create "${OPTS_VTAG_CREATE[@]}" --silent -- \
141 $_VSPACE --new "${OPTS_VSPACE[@]}" -- \
142 $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \
143 ${OPTION_STRACE:+$_STRACE -fF -o /tmp/vserver-start.$$} \
144 ${USE_VNAMESPACE:+$_VNAMESPACE --set -- } \
145 $_VSPACE --set "${OPTS_VSPACE[@]}" -- \
147 $_VLIMIT --dir "$VSERVER_DIR"/rlimits --missingok -- \
148 $_VSCHED --xid self --force "${OPTS_VSCHED[@]}" -- \
149 $_VSYSCTL --xid self --dir "$VSERVER_DIR"/sysctl --missingok -- \
150 $_VUNAME --xid self --dir "$VSERVER_DIR"/uts --missingok -- \
151 $_VMEMCTRL --xid self --set "${OPTS_VMEMCTRL[@]}" -- \
152 "${VSERVER_EXTRA_CMDS[@]}" \
153 $_VUNAME --xid self --set -t context="$VSERVER_DIR" -- \
154 $_VATTRIBUTE --set "${OPTS_VATTRIBUTE[@]}" -- \
155 $_SAVE_CTXINFO "$VSERVER_DIR" \
156 $_ENV -i "${OPTS_ENV[@]}" \
157 $_VCONTEXT --migrate-self --endsetup --chroot $SILENT_OPT \
158 "${OPTS_VCONTEXT_MIGRATE[@]}" "${OPTS_VCONTEXT_ENTER[@]}" -- \
159 "${INITCMD_START[@]}"
161 if test -n "$_IS_FAKEINIT"; then
162 startsync_pipe=$($_MKTEMP vserver-start.XXXXXX)
163 $_RM -f "$startsync_pipe"
164 $_MKFIFO -m600 "$startsync_pipe" ## safe, since mkfifo does not follow symlinks
170 $_EXEC_ULIMIT "$VSERVER_DIR/ulimits" \
171 $_CHCONTEXT_COMPAT "${CHCONTEXT_OPTS[@]}" "${CHCONTEXT_INIT_OPTS[@]}" \
172 $_SAVE_CTXINFO "$VSERVER_DIR" \
173 $_ENV -i "${OPTS_ENV[@]}" \
174 $_CHAINECHO "${_IS_FAKEINIT:+$startsync_pipe}" "" \
175 $_CAPCHROOT "${CAPCHROOT_OPTS[@]}" . \
176 "${INITCMD_START[@]}"
178 ## the additional synchronization step is needed since vshelper.doInit
179 ## below might be executed before needed context information were
180 ## saved by $_SAVE_CTXINFO
181 ${_IS_FAKEINIT:+cat "$startsync_pipe"} >/dev/null
185 "${INITCMD_START_SYNC[@]}"
188 pushd "$VSERVER_DIR"/vdir/ >/dev/null
189 execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" post-start
193 ! vshelper.isEnabled "" "$VSERVER_DIR" || vshelper.doInit "$VSERVER_DIR"