18273262ad85a4d905be7d8a35d5f29e7775c254
[util-vserver.git] / gentoo / util-vserver
1 #!/sbin/runscript
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 set_helper() {
6         local f="/proc/sys/kernel/vshelper"
7         if [ -e "$f" ]; then
8                 echo "$_VSHELPER" > "$f"
9         fi
10         return 0
11 }
12
13 kill_contexts() {
14         local xid
15         for xid in `ls -1 /proc/virtual`; do
16                 [ "$xid" = "info" -o "$xid" = "status" ] && continue
17                 $_VATTRIBUTE --xid $xid --set --flag ~persistent
18                 $_VKILL --xid $xid -s 15
19                 sleep 3
20                 $_VKILL --xid $xid -s 9
21         done
22         local alive=0
23         for xid in `ls -1 /proc/virtual`; do
24                 [ "$xid" = "info" -o "$xid" = "status" ] && continue
25                 let alive+=1
26         done
27         return $alive
28 }
29
30 start() {
31         : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
32         if [[ ! -e ${UTIL_VSERVER_VARS} ]]; then
33                 eerror "Cannot find util-vserver installation"
34                 eerror "(the file '$UTIL_VSERVER_VARS' would be expected)"
35                 return 1
36         fi
37         
38         source ${UTIL_VSERVER_VARS}
39         source "$_LIB_FUNCTIONS"
40         source "$__PKGLIBDIR/vserver.functions"
41
42         ebegin "Setting vshelper path to $_VSHELPER"
43         set_helper
44         eend $?
45
46         ebegin "Loading default device map"
47         loadDeviceMap 0 "$__CONFDIR/.defaults/apps/vdevmap"
48         eend $?
49 }
50
51 stop() {
52         : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
53         if [[ ! -e ${UTIL_VSERVER_VARS} ]]; then
54                 eerror "Cannot find util-vserver installation"
55                 eerror "(the file '$UTIL_VSERVER_VARS' would be expected)"
56                 return 1
57         fi
58         
59         source ${UTIL_VSERVER_VARS}
60         source "$_LIB_FUNCTIONS"
61         source "$__PKGLIBDIR/vserver.functions"
62
63         ebegin "Stopping all running guests"
64         $_START_VSERVERS -j 1 --all --stop
65         eend $?
66
67         ebegin "Killing all running contexts"
68         kill_contexts
69         eend $?
70 }
71
72 # vim:ts=4:filetype=gentoo-init-d