expect slice initscript to implement stop and restart
[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 function start() {
28     [ -x $slicescript ] || return 0
29     echo $"Starting $prog" 
30     $slicescript start $slicename &>> /var/log/vinit &
31     touch ${lockfile}
32     return 0
33 }
34
35 function stop() {
36     [ -x $slicescript ] && $slicescript stop $slicename &>> /var/log/vinit &
37     # safe side
38     sleep 5
39     echo $"Stopping $prog "
40     killproc $basename
41     rm -f ${lockfile}
42 }
43
44 function restart () {
45     [ -x $slicescript ] || return 0
46     echo $"Restarting $prog"
47     $slicescript restart $slicename &>> /var/log/vinit &
48     return 0
49 }
50
51 function status () {
52     if [ -f ${lockfile} ] ; then
53         echo "$prog seems to have run"
54         return 0
55     else
56         echo "$prog apparently hasn't run"
57         return 1
58     fi
59
60
61 case "$1" in
62     start)
63         start
64         RETVAL=$?
65         ;;
66     stop)
67         stop
68         RETVAL=$?
69         ;;
70     restart)
71         restart
72         RETVAL=$?
73         ;;
74     status)
75         status 
76         RETVAL=$?
77         ;;
78     *)
79         echo $"Usage: $0 {start|stop|restart|status}"
80         exit 1
81         ;;
82 esac
83
84 exit $RETVAL