vshost-util-vserver

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

vserver.stop (4015B)


      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" S_CONTEXT; then
     22     warning $"vserver '$VSERVER_NAME' is not running" >&2
     23     test -n "$OPTION_DEBUG" || exec 2>/dev/null >/dev/null
     24     umountVserver     "$VSERVER_DIR" || :
     25     disableInterfaces "$VSERVER_DIR" || :
     26     unlock
     27     exit 0
     28 fi
     29 
     30 function cleanup
     31 {
     32     set +e
     33     unlock
     34     
     35     test ! -p "$sync_fifo" || {
     36 	$_RM -f "$sync_fifo"
     37 	$_RMDIR $($_DIRNAME "$sync_fifo")
     38     }
     39 
     40     test ! -d "$vwait_statdir" ||
     41 	$_RM -rf "$vwait_statdir"
     42 }
     43 
     44 vwait_statdir=
     45 vwait_pid=
     46 sync_fifo=
     47 trap "cleanup" EXIT
     48 
     49 OPTION_FORCE_SYNC=1
     50 
     51 while test "$#" -gt 0; do
     52     case "$1" in
     53 	(--rescue-init)	shift; _IS_FAKEINIT=1;;
     54 	(--)		shift; break;;
     55 	(-*)		panic $"vserver ... stop: unknown option '$1'";;
     56     esac
     57 done
     58 
     59 set -e
     60 generateOptions   "$VSERVER_DIR"
     61 set +e
     62 
     63 vshelper.doDestroy "$VSERVER_DIR" "$S_CONTEXT"
     64 initSync           "$VSERVER_DIR" "$S_CONTEXT" sync_fifo
     65 prepareStop        "$VSERVER_DIR"
     66 enterNetNS         "$VSERVER_DIR"
     67 
     68 cd "$VSERVER_DIR"/vdir/
     69 execScriptlets     "$VSERVER_DIR" "$VSERVER_NAME" pre-stop
     70 cd "$VSERVER_DIR"/vdir/
     71 
     72 test -z "$OPTION_DEFAULTTTY" || setDefaultTTY "$VSERVER_DIR"
     73 
     74 $_VATTRIBUTE --set --xid "$S_CONTEXT" --flag !SC_HELPER
     75 
     76 fail=
     77 initWait	   "$VSERVER_DIR" "$S_CONTEXT" vwait_statdir
     78 if test -n "$_IS_FAKEINIT" && \
     79    $_VSERVER_INFO - FEATURE vkill; then
     80     if ! vshelper.isStopSync; then
     81 	$_VKILL -s INT --xid "$S_CONTEXT" -- 1 || fail=1
     82     fi
     83 elif $_VSERVER_INFO - FEATURE migrate; then
     84     "${IONICE_CMD[@]}" \
     85     "${NICE_CMD[@]}" \
     86     "${NETNS_CMD[@]}" \
     87     "${CHBIND_CMD[@]}" \
     88     "$_VSPACE" --enter "$S_CONTEXT" "${OPTS_VSPACE[@]}" "${OPTS_VSPACE_SHARED[@]}" -- \
     89     "$_VTAG" --migrate "${OPTS_VTAG_ENTER[@]}" --silent -- \
     90     $_VCONTEXT $SILENT_OPT --migrate $OPT_VCONTEXT_CHROOT --xid "$S_CONTEXT" -- \
     91     "${INITCMD_STOP[@]}" || fail=1
     92 else
     93     "${IONICE_CMD[@]}" \
     94     "${NICE_CMD[@]}" \
     95     "${CHBIND_CMD[@]}" \
     96     "$_EXEC_ULIMIT"  "$VSERVER_DIR/ulimits" \
     97     $_CHCONTEXT_COMPAT    "${CHCONTEXT_OPTS[@]}" \
     98     "$_CAPCHROOT"    "${CAPCHROOT_OPTS[@]}" "." \
     99     "${INITCMD_STOP[@]}" || fail=1
    100 fi
    101 
    102 # Remove persistent so those contexts can be stopped
    103 $_VATTRIBUTE --set --xid "$S_CONTEXT" --flag !persistent 2>/dev/null || :
    104 if $_VSERVER_INFO -q "$N_CONTEXT" XIDTYPE static &&
    105    $_VSERVER_INFO - FEATURE vnet; then
    106     $_NATTRIBUTE --set --nid "$N_CONTEXT" --flag !persistent 2>/dev/null || :
    107 fi
    108 
    109 vshelper.doStopSync
    110 
    111 waitForSync "$VSERVER_DIR" "$sync_fifo" "$vwait_statdir"
    112 
    113 vshelper.doDestroy "$VSERVER_DIR" "$S_CONTEXT"
    114 sendKillSequence   "$S_CONTEXT" "${INITKILL_SEQ[@]}"
    115 
    116 ## Small hack... isVserverRunning removes stale runfiles as a sideeffect
    117 ! isVserverRunning  "$VSERVER_DIR" || \
    118     echo $"Vserver '$VSERVER_DIR' still running unexpectedly; please investigate it manually..." >&2
    119 
    120 execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" post-stop
    121 
    122 handleDeviceMap --unset "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
    123 
    124 umountVserver     "$VSERVER_DIR" || :
    125 disableInterfaces "$VSERVER_DIR"
    126 
    127 saveDiskLimits    "$VSERVER_DIR"
    128 
    129 execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" postpost-stop
    130 removeCPUSET      "$VSERVER_DIR"
    131 destroyCgroup     "$VSERVER_DIR"
    132 destroyNetNS      "$VSERVER_DIR"