]> git.pld-linux.org Git - packages/util-vserver.git/blob - vservers.init
- rel 2; build with glibc, so it will also work on systems with newer kernels that...
[packages/util-vserver.git] / vservers.init
1 #!/bin/sh
2 #
3 # vservers:     starts and stops vservers
4 #
5 # chkconfig:    345 98 02
6 # description:  Wrapper to start and stop vservers
7 #               This script does not care for vservers not started by it
8 #
9 # Copyright 1999-2004 Gentoo Foundation
10 # Modified for PLD by Jan RÄ™korajski <baggins@pld-linux.org>
11 # Distributed under the terms of the GNU General Public License v2
12 #
13
14 # Source function library
15 . /etc/rc.d/init.d/functions
16
17 [ -n "$UTIL_VSERVER_VARS" ] || UTIL_VSERVER_VARS=/usr/share/util-vserver/util-vserver-vars
18 if [ ! -e "$UTIL_VSERVER_VARS" ] ; then
19         echo "Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
20         exit 1
21 fi
22 . "$UTIL_VSERVER_VARS"
23
24 [ -f /etc/sysconfig/vservers ] && . /etc/sysconfig/vservers
25
26 [ -n "$NUMPARALLEL" ] || NUMPARALLEL=1
27 [ -n "$LOCKDIR" ] || LOCKDIR="/var/lock/vservers"
28
29 _tellResult()
30 {
31         local rc=$1
32         deltext
33         case "$rc" in
34           0) ok;;
35           2) ok; rc=0;;
36           *) fail;;
37         esac
38         return $rc
39 }
40
41 case "$1" in
42 start)
43         if [ ! -f /var/lock/subsys/vprocunhide ]; then
44                 echo "Run \"/sbin/service vprocunhide start\" first"
45                 exit 1
46         fi
47
48         if is_yes "$STARTALL"; then
49                 if [ ! -f /var/lock/subsys/vservers-all ]; then
50                         show "Starting all types of vservers"
51                         busy
52                         $_START_VSERVERS -j $NUMPARALLEL --all --start
53                         _tellResult $?
54                         rc=$?
55                         [ $rc -eq 0 ] && touch /var/lock/subsys/vservers-all
56                 else
57                         echo "All types of vservers are already startred"
58                 fi
59         else
60                 for MARK in $MARKS; do
61                         if [ -f /var/lock/subsys/vservers-$MARK ]; then
62                                 echo "Vservers of type '$MARK' are already startred"
63                                 continue
64                         fi
65                         show "Starting vservers of type '$MARK'"
66                         busy
67                         $_START_VSERVERS -m $MARK -j $NUMPARALLEL --all --start
68                         _tellResult $?
69                         rc=$?
70                         [ $rc -eq 0 ] && touch /var/lock/subsys/vservers-$MARK
71                 done
72         fi
73
74         for VSERVER in $START_VSERVERS; do
75                 if [ -f /var/lock/subsys/vserver-$VSERVER ]; then
76                         echo "Vserver '$VSERVER' is already startred"
77                         continue
78                 fi
79                 show "Starting single vserver '$VSERVER'"
80                 busy
81                 $_VSERVER $VSERVER start
82                 _tellResult $?
83                 rc=$?
84                 [ $rc -eq 0 ] && touch /var/lock/subsys/vserver-$VSERVER
85         done
86         touch /var/lock/subsys/vservers
87         ;;
88 stop)
89         __STOP_VSERVERS=
90         for __V in $START_VSERVERS; do
91                 __STOP_VSERVERS="$__V $__STOP_VSERVERS"
92         done
93         for VSERVER in $__STOP_VSERVERS; do
94                 if [ ! -f /var/lock/subsys/vserver-$VSERVER ]; then
95                         echo "Vserver '$VSERVER' is not running"
96                         continue
97                 fi
98                 show "Stopping single vserver '$VSERVER'"
99                 busy
100                 $_VSERVER $VSERVER stop
101                 _tellResult $?
102                 rc=$?
103                 rm -f /var/lock/subsys/vserver-$VSERVER
104         done
105
106         if is_yes "$STARTALL"; then
107                 if [ -f /var/lock/subsys/vservers-all ]; then
108                         show "Stopping all types of vservers"
109                         busy
110                         $_START_VSERVERS -j $NUMPARALLEL --all --stop
111                         _tellResult $?
112                         rc=$?
113                         rm -f /var/lock/subsys/vservers-all
114                 else
115                         echo "All types of vservers are not running"
116                 fi
117         else
118                 __STOP_MARKS=
119                 for __V in $MARKS; do
120                         __STOP_MARKS="$__V $__STOP_MARKS"
121                 done
122                 for MARK in $__STOP_MARKS; do
123                         if [ ! -f /var/lock/subsys/vservers-$MARK ]; then
124                                 echo "Vservers of type '$MARK' are not running"
125                                 continue
126                         fi
127                         show "Stopping vservers of type '$MARK'"
128                         busy
129                         $_START_VSERVERS -m $MARK -j $NUMPARALLEL --all --stop
130                         _tellResult $?
131                         rc=$?
132                         rm -f /var/lock/subsys/vservers-$MARK
133                 done
134         fi
135         rm -f /var/lock/subsys/vservers
136         ;;
137 status)
138         echo "The following types of vservers are running:"
139
140         for i in /var/lock/subsys/vservers-*; do
141                 [ -f "$i" ] || continue
142                 echo $i | awk '{gsub("/var/lock/subsys/vservers-",""); printf(" %s\n",$0); }'
143                 running="true"
144         done
145
146         if [[ "${running}" != "true" ]]; then
147                 echo "  none"
148         fi
149
150         echo
151         echo "/proc/virtual/ says these are running:"
152
153         for i in /proc/virtual/*; do
154                 [ -d $i ] || continue
155                 NAME=$( basename $( vuname -g --xid $( basename ${i} ) CONTEX ) )
156                 echo "  ${NAME}"
157         done
158
159         echo
160         echo "vserver-stat says these are running:"
161         /usr/sbin/vserver-stat
162         ;;
163 *)
164         msg_usage "$0 {start|stop|status}"
165         exit 3
166         ;;
167 esac
168
169 exit $RETVAL
170
171 # This must be last line !
172 # vi:syntax=sh
This page took 0.034251 seconds and 3 git commands to generate.