#!/bin/bash

# Source function library.
. /etc/rc.status
. /etc/rc.config

RETVAL=0

start_daemon() {
	[ -f /sbin/$1 ] || return
	echo -n $"Starting $1: "
	checkproc /sbin/$1
	if [ $? -eq 0 ]; then
		echo -n " - already running ! "
	fi
	startproc -u root -g root /sbin/$1 $2
	rc_status
	rc_status -v
}

stop_daemon() {
	[ -f /sbin/$1 ] || return
	echo -n $"Stopping $1: "
	checkproc /sbin/$1 || echo -n "- not running !"
	killproc -TERM /sbin/$1 
	rc_status -v
}	

start_driver() {
	echo -n $"Inserting $1.o" 
	sh /opt/compaq/cpqci/cp$1 start
	rc_status
	rc_status -v
}

stop_driver() {
	echo -n $"Removing $1.o" 
	sh /opt/compaq/cpqci/cp$1 stop
	rc_status
	rc_status -v
}	

# See how we were called.
case "$1" in
  start)
	start_driver cpqci
	start_daemon cpqriisd -F
	;;
  stop)
	stop_daemon cpqriisd
	stop_driver cpqci
	;;
  restart)
	stop_daemon cpqriisd
	stop_driver cpqci
	start_driver cpqci
	start_daemon cpqriisd -F
	;;
  status|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
