erroneously checked in
[codemux.git] / codemux.initscript
1 #!/bin/sh
2 #
3 # chkconfig: 345 85 02
4 # description: codemux startup script
5 #
6
7 PROC=codemux
8
9 . /etc/rc.d/init.d/functions
10
11 RETVAL=0
12
13 pidfile=/var/run/$PROC.pid
14
15 check_status() {
16     pid=`cat $pidfile 2>/dev/null`
17     #
18     # this eliminates a race condition between checking existence of pidfile
19     # and reading its value
20     #
21     [ -n "$pid" -a -d /proc/$pid ]
22 }
23
24 case "$1" in
25     start)
26         echo -n "starting $PROC:"
27         pid=`cat $pidfile 2>/dev/null`
28         if [ -n "$pid" ]; then
29             # check whether process really exists
30             # yes - don't try to start
31             [ -d /proc/$pid ] && action "already running" /bin/true && exit 1
32
33             # no - PID file is stale
34             rm -f $pidfile
35         fi
36
37         initlog -c /usr/local/planetlab/sbin/codemux
38
39         cmd=success
40         check_status && touch /var/lock/subsys/$PROC || cmd=failure
41         $cmd "$PROC startup"
42         echo
43         ;;
44
45     stop)
46         echo -n "shutting down $PROC: "
47         killproc $PROC
48         RETVAL=$?
49         echo
50         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROC
51         ;;
52
53     restart|reload)
54         $0 stop
55         $0 start
56         RETVAL=$?
57         ;;
58
59     status)
60         check_status && echo 'running' && exit 0 || \
61             echo 'not running' && exit 1
62         ;;
63
64     *)
65         echo "Usage: $0 {start|stop|restart|status}"
66         RETVAL=1
67 esac
68
69 exit $RETVAL