File: vserver.stop

package info (click to toggle)
util-vserver 0.30.216-pre2864-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,576 kB
  • ctags: 4,462
  • sloc: ansic: 23,615; sh: 15,550; xml: 1,893; makefile: 402; python: 301; perl: 85; awk: 4
file content (129 lines) | stat: -rw-r--r-- 3,945 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# $Id: vserver.stop 2819 2008-10-31 15:41:04Z dhozac $  --*- 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")
    }

    test ! -d "$vwait_statdir" ||
	$_RM -rf "$vwait_statdir"
}

vwait_statdir=
vwait_pid=
sync_fifo=
trap "cleanup" EXIT

OPTION_FORCE_SYNC=1

while test "$#" -gt 0; do
    case "$1" in
	(--rescue-init)	shift; _IS_FAKEINIT=1;;
	(--)		shift; break;;
	(-*)		panic $"vserver ... stop: unknown option '$1'";;
    esac
done

set -e
generateOptions   "$VSERVER_DIR"
set +e

vshelper.doDestroy "$VSERVER_DIR" "$S_CONTEXT"
initSync           "$VSERVER_DIR" "$S_CONTEXT" 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"

$_VATTRIBUTE --set --xid "$S_CONTEXT" --flag !SC_HELPER

fail=
initWait	   "$VSERVER_DIR" "$S_CONTEXT" vwait_statdir
if test -n "$_IS_FAKEINIT" && \
   $_VSERVER_INFO - FEATURE vkill; then
    if ! vshelper.isStopSync; then
	$_VKILL -s INT --xid "$S_CONTEXT" -- 1 || fail=1
    fi
elif $_VSERVER_INFO - FEATURE migrate; then
    "${IONICE_CMD[@]}" \
    "${NICE_CMD[@]}" \
    "${CHBIND_CMD[@]}" \
    "$_VSPACE" --enter "$S_CONTEXT" "${OPTS_VSPACE[@]}" -- \
    "$_VTAG" --migrate "${OPTS_VTAG_ENTER[@]}" --silent -- \
    $_VCONTEXT $SILENT_OPT --migrate $OPT_VCONTEXT_CHROOT --xid "$S_CONTEXT" -- \
    "${INITCMD_STOP[@]}" || fail=1
else
    "${IONICE_CMD[@]}" \
    "${NICE_CMD[@]}" \
    "${CHBIND_CMD[@]}" \
    "$_EXEC_ULIMIT"  "$VSERVER_DIR/ulimits" \
    $_CHCONTEXT_COMPAT    "${CHCONTEXT_OPTS[@]}" \
    "$_CAPCHROOT"    "${CAPCHROOT_OPTS[@]}" "." \
    "${INITCMD_STOP[@]}" || fail=1
fi

# Remove persistent so those contexts can be stopped
$_VATTRIBUTE --set --xid "$S_CONTEXT" --flag !persistent 2>/dev/null || :
if $_VSERVER_INFO -q "$N_CONTEXT" XIDTYPE static &&
   $_VSERVER_INFO - FEATURE vnet; then
    $_NATTRIBUTE --set --nid "$N_CONTEXT" --flag !persistent 2>/dev/null || :
fi

vshelper.doStopSync

waitForSync "$VSERVER_DIR" "$sync_fifo" "$vwait_statdir"

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

handleDeviceMap --unset "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"

umountVserver     "$VSERVER_DIR" || :
disableInterfaces "$VSERVER_DIR"

saveDiskLimits    "$VSERVER_DIR"

execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" postpost-stop
removeCPUSET      "$VSERVER_DIR"
destroyCgroup     "$VSERVER_DIR"