Tagging module CoDemux - CoDemux-0.1-8
[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/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         killproc $PROC
49         RETVAL=$?
50         echo
51         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROC
52         ;;
53
54     restart|reload)
55         $0 stop
56         $0 start
57         RETVAL=$?
58         ;;
59
60     status)
61         check_status && echo 'running' && exit 0 || \
62             echo 'not running' && exit 1
63         ;;
64
65     *)
66         echo "Usage: $0 {start|stop|restart|status}"
67         RETVAL=1
68 esac
69
70 exit $RETVAL