2e4df9f8372d1246463e6af885f210e2ac8dea2d
[util-vserver.git] / scripts / vserver-wrapper
1 #! /bin/bash
2
3 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 #  
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
8 #  
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #  
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
19 test -e "$UTIL_VSERVER_VARS" || {
20     echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
21     exit 1
22 }
23 . "$UTIL_VSERVER_VARS"
24
25 test -n "$MARK" || MARK=default
26 : ${LOCKFILE:=vservers-$MARK}
27 : ${NUMPARALLEL:=6}
28
29
30 if test -e /etc/init.d/functions; then
31     . /etc/init.d/functions
32     _beginResult() { echo -n "$@"; }
33     lockfile=/var/lock/subsys/$LOCKFILE
34 elif test -e /etc/gentoo-release; then
35     . /sbin/functions.sh
36     _beginResult() { ebegin "$@"; }
37     success() { eend "$@"; }
38     passed()  { eend "$@"; }
39     failure() { eend "$@"; }
40     lockfile=/var/lock/vservers/$LOCKFILE
41 else
42     _beginResult() { echo -n "$@"; }
43     success() { echo .; }
44     passed()  { echo .; }
45     failure() { echo ERROR; }
46     lockfile=/var/run/$LOCKFILE
47 fi
48
49 function _tellResult()
50 {
51     local rc=$1
52     case "$rc" in
53         (0)     success;;
54         (2)     passed; rc=0;;
55         (*)     failure;;
56     esac
57     echo
58     return $rc
59 }
60
61 function start()
62 {
63     _beginResult $"Starting vservers of type '$MARK'..."
64     $_START_VSERVERS -m "$MARK" -j "$NUMPARALLEL" --all --start
65     _tellResult $?
66     local rc=$?
67     test "$rc" -ne 0 || touch "$lockfile"
68     return $rc
69 }
70
71 function stop()
72 {
73     _beginResult $"Stopping vservers of type '$MARK'..."
74     $_START_VSERVERS -m "$MARK" -j "$NUMPARALLEL" --all --stop
75     _tellResult $?
76     local rc=$?
77     $_RM -f "$lockfile"
78     return $rc
79 }
80
81 function restart()
82 {
83     stop
84     start
85 }
86
87 case "$1" in
88     start|stop|restart) $1;;
89     condrestart)
90         test -f $lockfile && restart || :
91         ;;
92     status)
93         test -f $lockfile && {
94             echo $"vservers of type '$MARK' were started"
95             exit 0
96         }
97         echo $"vservers of type '$MARK' are not started"
98         exit 1
99         ;;
100     *)
101         echo "Usage: $0 {start|stop|restart|condrestart|status}"
102         exit 2
103         ;;
104 esac