vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

vserver.start (6271B)


      1 # $Id$  --*- sh -*--
      2 
      3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
      4 #  
      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.
      8 #  
      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.
     13 #  
     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.
     17 
     18 
     19 lock "$__LOCKDIR"/vserver."$($_VSERVER_INFO "$VSERVER_DIR" CANONIFY)".startup
     20 
     21 if isVserverRunning "$VSERVER_DIR"; then
     22     warning $"vserver '$VSERVER_NAME' already running"
     23     exit 0
     24 fi
     25 
     26 function cleanup()
     27 {
     28     set +e
     29 
     30     test -z "$startsync_pipe"  || $_RM -f "$startsync_pipe"
     31     test -z "$is_started"      || { unlock; return 0; }
     32 
     33     if test -n "$is_configured" -a -z "$is_executed"; then
     34 	warning $"
     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.
     38 
     39 Common causes are:
     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."
     43     fi
     44 
     45     if test -n "$is_executed"; then
     46 	warning $"
     47 An error occured after executing the vserver startup sequence. This
     48 means that some processes may exist in the created context and the
     49 manual execution of
     50 
     51   $_VSERVER '$VSERVER_DIR' stop
     52 
     53 is recommended to fix this."
     54     else
     55 	warning $"
     56 
     57 Failed to start vserver '$VSERVER_NAME'"
     58     fi
     59 
     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" || :
     63     test -z "$have_cgroup"     || destroyCgroup     "$VSERVER_DIR" || :
     64 
     65     unlock || :
     66 }
     67 
     68 is_configured=
     69 is_executed=
     70 is_started=
     71 is_mounted=
     72 is_vshelper_init=
     73 have_interfaces=
     74 startsync_pipe=
     75 have_initcmd=
     76 have_cgroup=
     77 
     78 while test "$#" -gt 0; do
     79     case "$1" in
     80 	(--rescue)	INITSTYLE=rescue;;
     81 	(--rescue-cmd)
     82 	    warning $"\
     83 The '--rescue-cmd' option is deprecated; just add the the initcmd
     84 inclusive its arguments to the cmdline."
     85 	    INITCMD_RESCUE=( $2 );
     86 	    have_initcmd=1
     87 	    shift;;
     88 	(--rescue-init)	_IS_FAKEINIT=1;;
     89 	(--)		shift; break;;
     90 	(-*)		panic $"vserver ... start: unknown option '$1'";;
     91 	(*)		break;
     92     esac
     93     shift
     94 done
     95 
     96 if test x"$INITSTYLE" = xrescue -a -z "$have_initcmd" -a "$#" -gt 0; then
     97     INITCMD_RESCUE=( "$@" )
     98 fi
     99 
    100 
    101 set -e
    102 trap "cleanup" EXIT
    103 
    104 sanityCheck      "$VSERVER_DIR"
    105 
    106 pushd "$VSERVER_DIR" >/dev/null
    107 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" initialize
    108 popd >/dev/null
    109 
    110 fsckAllFS        "$VSERVER_DIR"
    111 
    112 mountRootFS      "$VSERVER_DIR"
    113 generateOptions  "$VSERVER_DIR"
    114 
    115 pushd "$VSERVER_DIR" >/dev/null
    116 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" prepre-start
    117 popd >/dev/null
    118 
    119 setDiskLimits    "$VSERVER_DIR"
    120 
    121 enableInterfaces "$VSERVER_DIR" && have_interfaces=1
    122 
    123 mountVserver     "$VSERVER_DIR" && is_mounted=1
    124 prepareInit      "$VSERVER_DIR"
    125 addtoCPUSET      "$VSERVER_DIR"
    126 attachToCgroup   "$VSERVER_DIR" && have_cgroup=1
    127 setupNetNS       "$VSERVER_DIR"
    128 
    129 handleDeviceMap --set "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
    130 
    131 pushd "$VSERVER_DIR"/vdir/ >/dev/null
    132 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" pre-start
    133 popd >/dev/null
    134 
    135 test -z "$OPTION_DEFAULTTTY" || setDefaultTTY "$VSERVER_DIR"
    136 
    137 pushd "$VSERVER_DIR"/vdir/ >/dev/null
    138 is_configured=1
    139 if $_VSERVER_INFO - FEATURE migrate; then
    140     ${IONICE_CMD[@]} \
    141     ${NICE_CMD[@]} \
    142     "${NETNS_CMD[@]}" \
    143     "${VSPACE_SHARED_CMD[@]}" \
    144     "${CHBIND_CMD[@]}" \
    145     $_EXEC_ULIMIT "$VSERVER_DIR"/ulimits \
    146     $_VTAG       --create "${OPTS_VTAG_CREATE[@]}" --silent -- \
    147     $_VSPACE     --new "${OPTS_VSPACE[@]}" -- \
    148     $_VCONTEXT   --create "${OPTS_VCONTEXT_CREATE[@]}" -- \
    149     ${OPTION_STRACE:+$_STRACE -fF -o /tmp/vserver-start.$$} \
    150     ${USE_VNAMESPACE:+$_VNAMESPACE --set -- } \
    151     $_VSPACE     --set "${OPTS_VSPACE[@]}" "${OPTS_VSPACE_SHARED[@]}" -- \
    152     $_EXEC_REMOUNT /proc /sys -- \
    153     $_VLIMIT     --dir "$VSERVER_DIR"/rlimits --missingok -- \
    154     $_VSCHED     --xid self --force "${OPTS_VSCHED[@]}" -- \
    155     $_VSYSCTL    --xid self --dir "$VSERVER_DIR"/sysctl --missingok -- \
    156     $_VUNAME     --xid self --dir "$VSERVER_DIR"/uts    --missingok -- \
    157     $_VMEMCTRL   --xid self --set "${OPTS_VMEMCTRL[@]}" -- \
    158     "${VSERVER_EXTRA_CMDS[@]}" \
    159     $_VUNAME     --xid self --set -t context="$VSERVER_DIR" -- \
    160     $_VATTRIBUTE --set "${OPTS_VATTRIBUTE[@]}" -- \
    161     $_SAVE_CTXINFO "$VSERVER_DIR" \
    162     $_ENV -i "${OPTS_ENV[@]}" \
    163     $_VCONTEXT   --migrate-self --endsetup $OPT_VCONTEXT_CHROOT $OPT_VCONTEXT_CLOSE_FD $SILENT_OPT \
    164     "${OPTS_VCONTEXT_MIGRATE[@]}" "${OPTS_VCONTEXT_ENTER[@]}" -- \
    165     "${INITCMD_START[@]}"
    166 else
    167     if test -n "$_IS_FAKEINIT"; then
    168 	startsync_pipe=$($_MKTEMP vserver-start.XXXXXX)
    169 	$_RM -f "$startsync_pipe"
    170 	$_MKFIFO -m600 "$startsync_pipe"	## safe, since mkfifo does not follow symlinks
    171     fi
    172     
    173     ${IONICE_CMD[@]} \
    174     ${NICE_CMD[@]} \
    175     "${CHBIND_CMD[@]}" \
    176     $_EXEC_ULIMIT      "$VSERVER_DIR/ulimits" \
    177     $_CHCONTEXT_COMPAT "${CHCONTEXT_OPTS[@]}" "${CHCONTEXT_INIT_OPTS[@]}" \
    178     $_SAVE_CTXINFO     "$VSERVER_DIR" \
    179     $_ENV -i "${OPTS_ENV[@]}" \
    180     $_CHAINECHO "${_IS_FAKEINIT:+$startsync_pipe}" "" \
    181     $_CAPCHROOT        "${CAPCHROOT_OPTS[@]}" . \
    182     "${INITCMD_START[@]}"
    183 
    184     ## the additional synchronization step is needed since vshelper.doInit
    185     ## below might be executed before needed context information were
    186     ## saved by $_SAVE_CTXINFO
    187     ${_IS_FAKEINIT:+cat "$startsync_pipe"} >/dev/null
    188 fi
    189 is_executed=1
    190 
    191 "${INITCMD_START_SYNC[@]}"
    192 popd >/dev/null
    193 
    194 pushd "$VSERVER_DIR"/vdir/ >/dev/null
    195 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" post-start
    196 popd >/dev/null
    197 
    198 is_vshelper_init=1
    199 ! vshelper.isEnabled "" "$VSERVER_DIR" || vshelper.doInit "$VSERVER_DIR"
    200 
    201 is_started=1