Move initscript functions to vserver-init.functions.
[util-vserver.git] / sysv / util-vserver
1 #!/bin/bash
2 #
3 # util-vserver  sets the path to vshelper and kills all guest processes
4 #
5 # chkconfig: 2345 10 90
6 # description: Sets the path to vshelper and kills all guest processes
7
8 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
9 test -e "$UTIL_VSERVER_VARS" || {
10     echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
11     exit 1
12 }
13 . "$UTIL_VSERVER_VARS"
14
15 LOCKFILE=util-vserver
16 . "$_LIB_VSERVER_INIT_FUNCTIONS"
17
18
19 function set_helper()
20 {
21     local f="/proc/sys/kernel/vshelper"
22     if test -e "$f"; then
23         echo "$_VSHELPER" > "$f"
24         return 0
25     else
26         return 2
27     fi
28 }
29
30 function kill_contexts()
31 {
32     for xid in `ls -1 /proc/virtual`; do
33         test "$xid" = "info" -o "$xid" = "status" && continue
34         $_VATTRIBUTE --xid $xid --set --flag ~persistent
35         $_VKILL --xid $xid -s 15
36         sleep 3
37         $_VKILL --xid $xid -s 9
38     done
39 }
40
41 function start()
42 {
43     _beginResult $"Setting path to vshelper"
44     set_helper
45     _endResult $?
46     local retval=$?
47     test "$retval" -ne 0 || touch "$lockfile"
48     return $retval
49 }
50
51 function stop()
52 {
53     # Stop all running, but non-default guests"
54     _beginResult $"Stopping all running guests"
55     $_START_VSERVERS -j 1 --all --stop
56     _endResult $?
57     local retval=$?
58     _beginResult $"Killing all running contexts"
59     kill_contexts
60     _endResult $?
61     $_RM -f "$lockfile"
62 }
63
64 function restart()
65 {
66     stop
67     start
68 }
69
70 case "$1" in
71     start|stop|restart) $1;;
72     reload)             ;;
73     condrestart)
74         test -f $lockfile && restart || :
75         ;;
76     status)
77         test -f $lockfile && {
78             echo $"/proc entries were fixed"
79             exit 0
80         }
81         echo $"/proc entries are not fixed"
82         exit 1
83         ;;
84     *)
85         echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
86         exit 2
87         ;;
88 esac