5f55b551a821e65bb92d0d60af230dfd2d1d84ee
[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 $"(Dummy) Stopping $prog "
46     rm -f ${lockfile}
47 }
48
49 function status () {
50     if [ -f ${lockfile} ] ; then
51         echo "$prog seems to have run"
52         return 0
53     else
54         echo "$prog apparently hasn't run"
55         return 1
56     fi
57
58
59 case "$1" in
60     start)
61         start
62         RETVAL=$?
63         ;;
64     stop)
65         stop
66         RETVAL=$?
67         ;;
68     status)
69         status 
70         RETVAL=$?
71         ;;
72     *)
73         echo $"Usage: $0 {start|stop|status}"
74         exit 1
75         ;;
76 esac
77
78 exit $RETVAL