]>
Commit | Line | Data |
---|---|---|
6faf1615 JR |
1 | #!/bin/sh |
2 | # | |
3 | # util-vserver: sets the path to vshelper and kills all guest processes | |
4 | # | |
8bd9732e | 5 | # chkconfig: 2345 10 70 |
6faf1615 JR |
6 | # description: Sets the path to vshelper and kills all guest processes |
7 | ||
0cfda7b7 JR |
8 | # if kernel not capable, exit early |
9 | if [ ! -d /proc/virtual ]; then | |
10 | case "$1" in | |
11 | start|stop|reload|force-reload|restart) | |
12 | exit 0 | |
13 | ;; | |
14 | esac | |
15 | fi | |
16 | ||
6faf1615 JR |
17 | # Source function library |
18 | . /etc/rc.d/init.d/functions | |
19 | ||
20 | [ -n "$UTIL_VSERVER_VARS" ] || UTIL_VSERVER_VARS=/usr/lib/util-vserver/util-vserver-vars | |
21 | if [ ! -e "$UTIL_VSERVER_VARS" ] ; then | |
22 | echo "Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2 | |
23 | exit 1 | |
24 | fi | |
25 | . "$UTIL_VSERVER_VARS" | |
26 | ||
27 | start() | |
28 | { | |
29 | show "Setting path to vshelper" | |
30 | if [ -e /proc/sys/kernel/vshelper ]; then | |
31 | echo "$_VSHELPER" >/proc/sys/kernel/vshelper | |
32 | ok | |
0cfda7b7 | 33 | RETVAL1=0 |
6faf1615 JR |
34 | else |
35 | fail | |
0cfda7b7 | 36 | RETVAL1=1 |
6faf1615 JR |
37 | fi |
38 | run_cmd "Loading default device map" $__PKGLIBDIR/bash-wrapper "handleDeviceMap --set 0 $__CONFDIR/.defaults/apps/vdevmap" | |
0cfda7b7 JR |
39 | RETVAL=$? |
40 | [ "$RETVAL" -eq 0 -a "$RETVAL1" -eq 0 ] && touch /var/lock/subsys/util-vserver | |
6faf1615 JR |
41 | } |
42 | ||
43 | # Stop all running, but non-default guests" | |
44 | stop() | |
45 | { | |
46 | run_cmd "Stopping all running guests" $_START_VSERVERS -j 1 --all --stop | |
47 | ||
621740e0 | 48 | xids=$(ls -1 /proc/virtual 2>/dev/null | egrep -v 'info|status' 2>/dev/null) |
6faf1615 JR |
49 | if [ -n "$xids" ]; then |
50 | show "Sending all contexts the TERM signal" | |
51 | for xid in $xids; do | |
52 | $_VATTRIBUTE --xid $xid --set --flag ~persistent | |
53 | $_VKILL --xid $xid -s 15 | |
54 | done | |
621740e0 | 55 | xids=$(ls -1 /proc/virtual 2>/dev/null | egrep -v 'info|status' 2>/dev/null) |
6faf1615 JR |
56 | if [ -n "$xids" ]; then |
57 | fail | |
58 | else | |
59 | ok | |
60 | fi | |
61 | fi | |
62 | if [ -n "$xids" ]; then | |
63 | sleep 5 | |
64 | show "Sending all contexts the KILL signal" | |
65 | for xid in $xids; do | |
66 | $_VATTRIBUTE --xid $xid --set --flag ~persistent | |
67 | $_VKILL --xid $xid -s 9 | |
68 | done | |
621740e0 | 69 | xids=$(ls -1 /proc/virtual 2>/dev/null | egrep -v 'info|status' 2>/dev/null) |
6faf1615 JR |
70 | if [ -n "$xids" ]; then |
71 | fail | |
72 | else | |
73 | ok | |
74 | fi | |
75 | fi | |
0cfda7b7 | 76 | rm -f /var/lock/subsys/util-vserver >/dev/null 2>&1 |
6faf1615 JR |
77 | } |
78 | ||
79 | RETVAL=0 | |
80 | # See how we were called. | |
81 | case "$1" in | |
82 | start) | |
83 | start | |
84 | ;; | |
85 | stop) | |
86 | stop | |
87 | ;; | |
f1ab4a3d JR |
88 | # restart behaves like reload because a stop-start sequence |
89 | # would kill all running vservers AND would not start them | |
0cfda7b7 | 90 | restart|reload|force-reload) |
6faf1615 JR |
91 | start |
92 | [ $? -ne 0 ] && RETVAL=7 | |
93 | ;; | |
94 | status) | |
95 | if [ -e /proc/sys/kernel/vshelper ]; then | |
96 | read _vsh </proc/sys/kernel/vshelper | |
97 | show "Path to vshelper: $_vsh, expected: $_VSHELPER" | |
98 | if [ "$_vsh" = "$_VSHELPER" ]; then | |
99 | ok | |
100 | RETVAL=0 | |
101 | else | |
102 | fail | |
103 | RETVAL=1 | |
104 | fi | |
105 | else | |
106 | RETVAL=1 | |
107 | fi | |
108 | ;; | |
109 | *) | |
110 | msg_usage "$0 {start|stop|restart|reload|force-reload|status}" | |
111 | exit 3 | |
112 | ;; | |
113 | esac | |
114 | ||
115 | exit $RETVAL |