4a3e9c7080bcb113c19fb802d428085e701c9a63
[nodemanager.git] / sliver-initscripts / vinit
1 #!/bin/bash
2 #
3 # $Id$
4 # $URL$
5 #
6 # vinit - trigger the slice-local initscript as installed in /etc/rc.d/vinit.slice
7 #
8 # this is unconditionnally installed and activated in the sliver
9 # but of course nothing is run if the script is not present 
10 #
11 # note - for practical reasons this is *not* activated through chkconfig
12 # as the slice has not yet started at that point
13 #
14 # historical note
15 # historically planetlab initscripts have not been required to handle the 'stop' method
16 # so installing such a script directly as /etc/rc.d/vinit would result in the
17 # script .. being run a second time at vserver-stop time
18
19
20 # Source function library.
21 . /etc/init.d/functions
22
23 slicescript=/etc/rc.d/init.d/vinit.slice
24 basename=$(basename $slicescript)
25 slicename=$(cat /etc/slicename)
26
27 prog="Slice initscript ${basename}@${slicename}"
28 lockfile=/var/lock/subsys/vinit
29
30 RETVAL=0
31
32 function start() {
33     if [ ! -x $slicescript ] ; then
34         echo "vinit@$slicename: no executable $slicescript - ignored"
35         return 0
36     fi
37     echo $"Starting $prog" 
38     $slicescript start $slicename >& /var/log/vinit &
39     touch ${lockfile}
40     return 0
41 }
42
43 # the initial model came without a stop function; legacy ...
44 function stop() {
45     echo $"Stopping $prog "
46     killproc $basename
47     rm -f ${lockfile}
48 }
49
50 function status () {
51     if [ -f ${lockfile} ] ; then
52         echo "$prog seems to have run"
53         return 0
54     else
55         echo "$prog apparently hasn't run"
56         return 1
57     fi
58
59
60 case "$1" in
61     start)
62         start
63         RETVAL=$?
64         ;;
65     stop)
66         stop
67         RETVAL=$?
68         ;;
69     status)
70         status 
71         RETVAL=$?
72         ;;
73     *)
74         echo $"Usage: $0 {start|stop|status}"
75         exit 1
76         ;;
77 esac
78
79 exit $RETVAL