]> git.pld-linux.org Git - packages/util-vserver.git/blob - vservers.init
- fix script
[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/lib/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 "$MARKS" ] || MARKS="default"
27 [ -n "$NUMPARALLEL" ] || NUMPARALLEL=1
28 [ -n "$LOCKDIR" ] || LOCKDIR="/var/lock/vservers"
29
30 _tellResult()
31 {
32         local rc=$1
33         deltext
34         case "$rc" in
35           0) ok;;
36           2) ok; rc=0;;
37           *) fail;;
38         esac
39         return $rc
40 }
41
42 case "$1" in
43 start)
44         if [ ! -f /var/lock/subsys/vprocunhide ]; then
45                 echo "Run \"/etc/rc.d/init.d/vprocunhide start\" first"
46                 exit 1
47         fi
48
49         if is_yes "$STARTALL"; then
50                 if [ ! -f /var/lock/subsys/vservers-all ]; then
51                         show "Starting all types of vservers"
52                         busy
53                         $_START_VSERVERS -j $NUMPARALLEL --all --start
54                         _tellResult $?
55                         rc=$?
56                         [ $rc -eq 0 ] && touch /var/lock/subsys/vservers-all
57                 else
58                         echo "All types of vservers are already startred"
59                 fi
60         else
61                 for MARK in $MARKS; do
62                         if [ -f /var/lock/subsys/vservers-$MARK ]; then
63                                 echo "Vservers of type '$MARK' are already startred"
64                                 continue
65                         fi
66                         show "Starting vservers of type '$MARK'"
67                         busy
68                         $_START_VSERVERS -m $MARK -j $NUMPARALLEL --all --start
69                         _tellResult $?
70                         rc=$?
71                         [ $rc -eq 0 ] && touch /var/lock/subsys/vservers-$MARK
72                 done
73         fi
74
75         for VSERVER in $START_VSERVERS; do
76                 if [ -f /var/lock/subsys/vserver-$VSERVER ]; then
77                         echo "Vserver '$VSERVER' is already startred"
78                         continue
79                 fi
80                 show "Starting single vserver '$VSERVER'"
81                 busy
82                 $_VSERVER $VSERVER start
83                 _tellResult $?
84                 rc=$?
85                 [ $rc -eq 0 ] && touch /var/lock/subsys/vserver-$VSERVER
86         done
87         ;;
88 stop)
89         for VSERVER in $START_VSERVERS; do
90                 if [ ! -f /var/lock/subsys/vserver-$VSERVER ]; then
91                         echo "Vserver '$VSERVER' is not running"
92                         continue
93                 fi
94                 show "Stopping single vserver '$VSERVER'"
95                 busy
96                 $_VSERVER $VSERVER stop
97                 _tellResult $?
98                 rc=$?
99                 rm -f /var/lock/subsys/vserver-$VSERVER
100         done
101
102         if is_yes "$STARTALL"; then
103                 if [ -f /var/lock/subsys/vservers-all ]; then
104                         show "Stopping all types of vservers"
105                         busy
106                         $_START_VSERVERS -j $NUMPARALLEL --all --stop
107                         _tellResult $?
108                         rc=$?
109                         rm -f /var/lock/subsys/vservers-all
110                 else
111                         echo "All types of vservers are not running"
112                 fi
113         else
114                 for MARK in $MARKS; do
115                         if [ ! -f /var/lock/subsys/vservers-$MARK ]; then
116                                 echo "Vservers of type '$MARK' are not running"
117                                 continue
118                         fi
119                         show "Stopping vservers of type '$MARK'"
120                         busy
121                         $_START_VSERVERS -m $MARK -j $NUMPARALLEL --all --stop
122                         _tellResult $?
123                         rc=$?
124                         rm -f /var/lock/subsys/vservers-$MARK
125                 done
126         fi
127         ;;
128 status)
129         echo "The following types of vservers are running:"
130
131         for i in /var/lock/subsys/vservers-*; do
132                 [ -f "$i" ] || continue
133                 echo $i | awk '{gsub("/var/lock/subsys/vservers-",""); printf(" %s\n",$0); }'
134                 running="true"
135         done
136
137         if [[ "${running}" != "true" ]]; then
138                 echo "  none"
139         fi
140
141         echo
142         echo "/proc/virtual/ says these are running:"
143
144         for i in /proc/virtual/*; do
145                 [ -d $i ] || continue
146                 NAME=$( basename $( vuname -g --xid $( basename ${i} ) CONTEX ) )
147                 echo "  ${NAME}"
148         done
149
150         echo
151         echo "vserver-stat says these are running:"
152         /usr/sbin/vserver-stat
153         ;;
154 *)
155         echo "Usage: $0 {start|stop|status}"
156         exit 1
157         ;;
158 esac
159
160 exit $RETVAL
161
162 # This must be last line !
163 # vi:syntax=sh
This page took 0.059098 seconds and 4 git commands to generate.