#!/bin/sh
#
# $Id: rcad.rc.in,v 1.1.2.13 2005/10/31 22:51:12 ejones Exp $
#
### BEGIN INIT INFO
# Provides:          rcadcompute
# Default-Start:     3
# Default-Stop:      0 1 2 5 6
# Description:       Start RCA
### END INIT INFO
PATH=/bin:/usr/bin:/usr/sbin:/sbin

case "$1" in
    start)
	rcad_svcs -b 10 -D -P "/sbin/rcad_svcs-helper -f /etc/rcad_svcs.conf" >/dev/null 2>&1 &
	;;
    stop)
	RCAD_NAME="rcad_svcs"
	RPID=""

	for file in /proc/*/stat;do
        	[ -f $file ] && read pid name junk < $file
	        if [ "($RCAD_NAME)" = "$name" ];then
	                RPID=$pid
	        fi
	done

	if [ -n "$RPID" ];then
	        SPID=""
	        kill -STOP $RPID
	        for file in /proc/*/stat;do                                             
                	[ -f $file ] && read pid name state ppid junk < $file                           
	                if [ "$ppid" = "$RPID" ];then                                   
	                        SPID="$pid $SPID"
	       	        fi                                                              
	        done
	        kill $SPID
	        sleep 1
	        kill -9 $SPID
	        kill -9 $RPID                                                           
	fi
	;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac
