]> git.pld-linux.org Git - packages/util-vserver.git/blob - util-vserver.init
- set vshelper path, kill all contexts on stop
[packages/util-vserver.git] / util-vserver.init
1 #!/bin/sh
2 #
3 # util-vserver: sets the path to vshelper and kills all guest processes
4 #
5 # chkconfig:    2345 10 99
6 # description:  Sets the path to vshelper and kills all guest processes
7
8 # Source function library
9 . /etc/rc.d/init.d/functions
10
11 [ -n "$UTIL_VSERVER_VARS" ] || UTIL_VSERVER_VARS=/usr/lib/util-vserver/util-vserver-vars
12 if [ ! -e "$UTIL_VSERVER_VARS" ] ; then
13         echo "Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
14         exit 1
15 fi
16 . "$UTIL_VSERVER_VARS"
17
18 start()
19 {
20         show "Setting path to vshelper"
21         if [ -e /proc/sys/kernel/vshelper ]; then
22                 echo "$_VSHELPER" >/proc/sys/kernel/vshelper
23                 ok
24         else
25                 fail
26         fi
27         run_cmd "Loading default device map" $__PKGLIBDIR/bash-wrapper "handleDeviceMap --set 0 $__CONFDIR/.defaults/apps/vdevmap"
28 }
29
30 # Stop all running, but non-default guests"
31 stop()
32 {
33         run_cmd "Stopping all running guests" $_START_VSERVERS -j 1 --all --stop
34
35         xids=$(cd /proc/virtual ; echo [0-9]*)
36         if [ -n "$xids" ]; then
37                 show "Sending all contexts the TERM signal"
38                 for xid in $xids; do
39                         $_VATTRIBUTE --xid $xid --set --flag ~persistent
40                         $_VKILL --xid $xid -s 15
41                 done
42                 xids=$(cd /proc/virtual ; echo [0-9]*)
43                 if [ -n "$xids" ]; then
44                         fail
45                 else
46                         ok
47                 fi
48         fi
49         if [ -n "$xids" ]; then
50                 sleep 5
51                 show "Sending all contexts the KILL signal"
52                 for xid in $xids; do
53                         $_VATTRIBUTE --xid $xid --set --flag ~persistent
54                         $_VKILL --xid $xid -s 9
55                 done
56                 xids=$(cd /proc/virtual ; echo [0-9]*)
57                 if [ -n "$xids" ]; then
58                         fail
59                 else
60                         ok
61                 fi
62         fi
63 }
64
65 RETVAL=0
66 # See how we were called.
67 case "$1" in
68   start)
69         start
70         ;;
71   stop)
72         stop
73         ;;
74   restart)
75         stop
76         start
77         ;;
78   reload|force-reload)
79         start
80         [ $? -ne 0 ] && RETVAL=7
81         ;;
82   status)
83         if [ -e /proc/sys/kernel/vshelper ]; then
84                 read _vsh </proc/sys/kernel/vshelper
85                 show "Path to vshelper: $_vsh, expected: $_VSHELPER"
86                 if [ "$_vsh" = "$_VSHELPER" ]; then
87                         ok
88                         RETVAL=0
89                 else
90                         fail
91                         RETVAL=1
92                 fi
93         else
94                 RETVAL=1
95         fi
96         ;;
97   *)
98         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
99         exit 3
100         ;;
101 esac
102
103 exit $RETVAL
This page took 0.037325 seconds and 4 git commands to generate.