#!/bin/bash

# Copyright 2000-2002, hp Computer Corporation.  All rights reserved.
#

PKGBIN=/opt/compaq/foundation/bin:/opt/compaq/server/bin
LOGFILE=/var/spool/compaq/cma.log
#NAME="agentname"
#PNAME="agentbind"
#PFLAGS="-p 120"

cmaecho () {
  echo "  " $*
  echo "  " $* >>$LOGFILE 2>&1
}

cmaechon () {
  echo -n "  " $*
  echo -n "  " $* >>$LOGFILE 2>&1
}

. /etc/rc.status
. /etc/rc.config

rc_reset

PATH=$PKGBIN:$PATH
case "$1" in
  start)
	pidlist=`pidof -o $$ $PNAME`
	if [ -z "$pidlist" ]; then
		cmaechon "Starting $NAME ($PNAME): "
		$PNAME $PFLAGS >> $LOGFILE 2>&1 
		rc_status -v
	else
		cmaecho "Already started $NAME ($PNAME). "
	fi
	;;
  stop)
	pidlist=`pidof -o $$ $PNAME`
	if [ -z "$pidlist" ]; then
		cmaecho "Already stopped $NAME ($PNAME). "
	else
		cmaechon "Shutting down $NAME ($PNAME): "
		killproc $PNAME 2>/dev/null
		rc_status -v
	fi
	;;
  restart)
	$0 stop
	$0 start
	;;
  status)
	cmaechon "Checking for $PNAME: "
	/sbin/checkproc $PNAME 
	rc_status -v
	;;
  *)
	cmaecho "Usage: $PNAME {start|stop|restart|status}"
	exit 1
esac
rc_exit
