#!/bin/sh

# Source function library.
. /etc/init.d/functions

# See how we were called.
case "$1" in
  start)
	action "Starting hp ProLiant Remote Insight Board Driver" \
	sh /opt/compaq/cpqrid/cpcpqrid start
	;;
  stop)
        MYPID=`ps -x | grep cmanic | awk '{ print $5 }'`
        for i in $MYPID
        do
                if [ "$i" != "grep" ]
                then
                        echo "WARNING: cmanic agent running!"
                        echo "         You must stop this process first."
                        echo "         usage:  /etc/rc.d/init.d/cmanic stop"
                        exit 1
                fi
        done
        MYPID=`ps -x | grep cmastor | awk '{ print $5 }'`
        for i in $MYPID
        do
                if [ "$i" != "grep" ]
                then
                        echo "WARNING: cmastor agent running!"
                        echo "         You must stop this process first."
                        echo "         usage:  /etc/rc.d/init.d/cmastor stop"
                        exit 1
                fi
        done
        MYPID=`ps -x | grep cmasvr | awk '{ print $5 }'`
        for i in $MYPID
        do
                if [ "$i" != "grep" ]
                then
                        echo "WARNING: cmasvr agent running!"
                        echo "         You must stop this process first."
                        echo "         usage:  /etc/rc.d/init.d/cmasvr stop"
                        exit 1
                fi
        done
        MYPID=`ps -x | grep cmafdtn | awk '{ print $5 }'`
        for i in $MYPID
        do
                if [ "$i" != "grep" ]
                then
                        echo "WARNING: cmafdtn agent running!"
                        echo "         You must stop this process first."
                        echo "         usage:  /etc/rc.d/init.d/cmafdtn stop"
                        exit 1
                fi
        done
	action "Stopping hp ProLiant Remote Insight Board Driver" \
	sh /opt/compaq/cpqrid/cpcpqrid stop
	;;
  status)
        echo "Here is the module executing:"
        lsmod |grep Module
        lsmod |grep cpqrid
	;;
  restart|reload)
	# do not do anything; this is unreasonable
	:
	;;
  *)
	# do not advertise unreasonable commands that there is no reason
	# to use with this device
	echo "Usage: random {start|stop|status|restart|reload}"
	exit 1
esac

exit 0
