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