1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
# $Id: vserver.stop,v 1.24 2005/01/27 21:24:44 ensc Exp $ --*- sh -*--
# Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# 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" S_CONTEXT; then
warning $"vserver '$VSERVER_NAME' is not running" >&2
test -n "$OPTION_DEBUG" || exec 2>/dev/null >/dev/null
umountVserver "$VSERVER_DIR" || :
disableInterfaces "$VSERVER_DIR" || :
unlock
exit 0
fi
function cleanup
{
set +e
unlock
test ! -p "$sync_fifo" || {
$_RM -f "$sync_fifo"
$_RMDIR $($_DIRNAME "$sync_fifo")
}
}
sync_fifo=
trap "cleanup" EXIT
set -e
generateOptions "$VSERVER_DIR"
set +e
vshelper.doDestroy "$VSERVER_DIR" "$S_CONTEXT"
initSync "$VSERVER_DIR" sync_fifo
prepareStop "$VSERVER_DIR"
cd "$VSERVER_DIR"/vdir/
execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" pre-stop
cd "$VSERVER_DIR"/vdir/
test -z "$OPTION_DEFAULTTTY" || setDefaultTTY "$VSERVER_DIR"
fail=
if test -n "$_IS_FAKEINIT" && \
$_VSERVER_INFO - FEATURE vkill && \
initpid=$($_VSERVER_INFO "$S_CONTEXT" INITPID 2>/dev/null); then
$_VKILL -s INT -- "$initpid" || fail=1
elif $_VSERVER_INFO - FEATURE migrate; then
"${NICE_CMD[@]}" \
${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT" -- } \
$_VCONTEXT $SILENT_OPT --migrate --chroot --xid "$S_CONTEXT" -- \
"${INITCMD_STOP[@]}" || fail=1
else
"${NICE_CMD[@]}" \
"$_CHBIND" "${CHBIND_OPTS[@]}" \
"$_EXEC_ULIMIT" "$VSERVER_DIR/ulimits" \
${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT"} \
$_CHCONTEXT_COMPAT "${CHCONTEXT_OPTS[@]}" \
"$_CAPCHROOT" "${CAPCHROOT_OPTS[@]}" "." \
"${INITCMD_STOP[@]}" || fail=1
fi
test -n "$fail" || waitForSync "$VSERVER_DIR" "$sync_fifo"
vshelper.doDestroy "$VSERVER_DIR" "$S_CONTEXT"
sendKillSequence "$S_CONTEXT" "${INITKILL_SEQ[@]}"
## Small hack... isVserverRunning removes stale runfiles as a sideeffect
! isVserverRunning "$VSERVER_DIR" || \
echo $"Vserver '$VSERVER_DIR' still running unexpectedly; please investigate it manually..." >&2
execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" post-stop
umountVserver "$VSERVER_DIR" || :
disableInterfaces "$VSERVER_DIR"
#
# <Bertl> it's a 'feature' introduced by recent kernels ...
# <Bertl> proc inodes stay around as long as they want to
# <Bertl> and processes too, even if they are dead
# <Bertl> as long as the process won't go away, the context will not either
# <Bertl> and the process won't go away, as long as the proc entry exists ...
# <Bertl> and the proc entry (in /proc/<pid>...) will remain until the proc inodes are purged
# <Bertl> maybe I just add a hack to do exactly that on vserver stop
# <Bertl> but you can also add the proc remount hack in userspace
#
mount -o remount,rw /proc
execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" postpost-stop
|