X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Fvserver.start;h=f3a8ff22918e0753cf4d6cc8b4c0e5df92c011dc;hb=d1f7d886a4cc0dcccafcd0fd7523bcedbc35ce27;hp=d67c7a11b9babb6c821adb51239e6b0d28c5e9f8;hpb=e035f164c858115c488d0f2fc1e0d356a9096996;p=util-vserver.git diff --git a/util-vserver/scripts/vserver.start b/util-vserver/scripts/vserver.start index d67c7a1..f3a8ff2 100644 --- a/util-vserver/scripts/vserver.start +++ b/util-vserver/scripts/vserver.start @@ -15,43 +15,145 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +lock "$__LOCKDIR"/vserver."$($_VSERVER_INFO "$VSERVER_DIR" CANONIFY)".startup + if isVserverRunning "$VSERVER_DIR"; then - echo $"vserver '$VSERVER_NAME' already running; aborting..." >&2 - exit 1 + warning $"vserver '$VSERVER_NAME' already running" + exit 0 fi +function cleanup() +{ + set +e + + test -z "$startsync_pipe" || $_RM -f "$startsync_pipe" + test -z "$is_started" || { unlock; return 0; } + + if test -n "$is_configured" -a -z "$is_executed"; then + warning $" +An error occured while executing the vserver startup sequence; when +there are no other messages, it is very likely that the init-script +(${INITCMD_START[@]}) failed. + +Common causes are: +* /etc/rc.d/rc on Fedora Core 1 and RH9 fails always; the 'apt-rpm' build + method knows how to deal with this, but on existing installations, + appending 'true' to this file will help." + fi + + if test -n "$is_executed"; then + warning $" +An error occured after executing the vserver startup sequence. This +means that some processes may exist in the created context and the +manual execution of + + $_VSERVER '$VSERVER_DIR' stop + +is recommended to fix this." + else + warning $" + +Failed to start vserver '$VSERVER_NAME'" + fi + + test -n "$OPTION_DEBUG" || exec 2>/dev/null >/dev/null + test -z "$is_mounted" || umountVserver "$VSERVER_DIR" || : + test -z "$have_interfaces" || disableInterfaces "$VSERVER_DIR" || : + + unlock || : +} + +is_configured= +is_executed= +is_started= +is_mounted= +is_vshelper_init= +have_interfaces= +startsync_pipe= + +while test "$#" -gt 0; do + case "$1" in + (--rescue) INITSTYLE=rescue;; + (--rescue-cmd) INITCMD_RESCUE=( $2 ); shift;; + (*) panic $"vserver ... start: unknown option '$1'";; + esac + shift +done + set -e +trap "cleanup" EXIT + +sanityCheck "$VSERVER_DIR" + +mountRootFS "$VSERVER_DIR" generateOptions "$VSERVER_DIR" + +pushd "$VSERVER_DIR" >/dev/null execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" prepre-start -enableInterfaces "$VSERVER_DIR" +popd + +enableInterfaces "$VSERVER_DIR" && have_interfaces=1 -mountVserver "$VSERVER_DIR" +mountVserver "$VSERVER_DIR" && is_mounted=1 prepareInit "$VSERVER_DIR" -cd "$VSERVER_DIR"/vdir/ +pushd "$VSERVER_DIR"/vdir/ >/dev/null execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" pre-start +popd >/dev/null -cd "$VSERVER_DIR"/vdir/ +test -z "$OPTION_DEFAULTTTY" || setDefaultTTY "$VSERVER_DIR" +pushd "$VSERVER_DIR"/vdir/ >/dev/null +is_configured=1 if $_VSERVER_INFO - FEATURE migrate; then - $_CHBIND "${CHBIND_OPTS[@]}" \ - $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" \ - ${USE_VNAMESPACE:+$_VNAMESPACE --set} \ - $_VLIMIT --dir "$VSERVER_DIR/rlimits" --missingok \ - $_VATTRIBUTE --set "${OPTS_VATTRIBUTE[@]}" \ - $_VCONTEXT --migrate --chroot $SILENT_OPT "${OPTS_VCONTEXT_MIGRATE[@]}" \ - -- "${INITCMD_START[@]}" + ${NICE_CMD[@]} \ + $_CHBIND "${CHBIND_OPTS[@]}" -- \ + $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \ + ${USE_VNAMESPACE:+$_VNAMESPACE --set -- } \ + $_VLIMIT --dir "$VSERVER_DIR"/rlimits --missingok -- \ + $_VSCHED --xid self "${OPTS_VSCHED[@]}" -- \ + $_VUNAME --xid self --dir "$VSERVER_DIR"/uts --missingok -- \ + "${VSERVER_EXTRA_CMDS[@]}" \ + $_VUNAME --xid self --set -t context="$VSERVER_DIR" -- \ + $_VATTRIBUTE --set "${OPTS_VATTRIBUTE[@]}" -- \ + $_SAVE_CTXINFO "$VSERVER_DIR" \ + $_ENV -i -- \ + $_VCONTEXT --migrate-self --endsetup --chroot $SILENT_OPT \ + "${OPTS_VCONTEXT_MIGRATE[@]}" "${OPTS_VCONTEXT_ENTER[@]}" -- \ + "${INITCMD_START[@]}" else - "${NICE_CMD[@]}" \ - "$_CHBIND" "${CHBIND_OPTS[@]}" \ - "$_EXEC_ULIMIT" "$VSERVER_DIR/ulimits" \ - "$_CHCONTEXT" "${CHCONTEXT_OPTS[@]}" "${CHCONTEXT_INIT_OPTS[@]}" \ - "$_SAVE_CTXINFO" "$VSERVER_DIR" \ - "$_CLEARENV" \ - "$_CAPCHROOT" "${CAPCHROOT_OPTS[@]}" . \ - -- "${INITCMD_START[@]}" + if test -n "$_IS_FAKEINIT"; then + startsync_pipe=$($_MKTEMP /tmp/vserver-start.XXXXXX) + $_RM -f "$startsync_pipe" + $_MKFIFO -m600 "$startsync_pipe" ## safe, since mkfifo does not follow symlinks + fi + + ${NICE_CMD[@]} \ + $_CHBIND "${CHBIND_OPTS[@]}" \ + $_EXEC_ULIMIT "$VSERVER_DIR/ulimits" \ + $_CHCONTEXT_COMPAT "${CHCONTEXT_OPTS[@]}" "${CHCONTEXT_INIT_OPTS[@]}" \ + $_SAVE_CTXINFO "$VSERVER_DIR" \ + $_ENV -i -- \ + $_CHAINECHO "${_IS_FAKEINIT:+$startsync_pipe}" "" \ + $_CAPCHROOT "${CAPCHROOT_OPTS[@]}" . \ + "${INITCMD_START[@]}" + + ## the additional synchronization step is needed since vshelper.doInit + ## below might be executed before needed context information were + ## saved by $_SAVE_CTXINFO + ${_IS_FAKEINIT:+cat "$startsync_pipe"} >/dev/null fi +is_executed=1 "${INITCMD_START_SYNC[@]}" +popd >/dev/null +pushd "$VSERVER_DIR"/vdir/ >/dev/null execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" post-start +popd >/dev/null + +is_vshelper_init=1 +! vshelper.isEnabled "" "$VSERVER_DIR" || vshelper.doInit "$VSERVER_DIR" + +is_started=1