#!/bin/sh

#############################################################################
# Copyright (C)2004-2005, Sun Microsystems Inc. All rights reserved.
# Use is subject to license terms.
#
# Name: cc-ccragent
# Description: CNS framework control script for the "CCR agent"
#
# pragma ident	"$Id: cc-ccragent,v 1.1.2.3 2005/04/28 21:26:45 rc5273 Exp $"
##############################################################################

################################################################################
#  Function:
#  1.  Starts the ccragent executable if the param received is 'start'
#  2.  Stops the ccragent executable if the param received is 'stop'
#   
#################################################################################

pid_file=/var/run/ccragent.pid
watchdog=`/usr/lib/cc-cfw/framework/lib/get_interface WATCHDOG`
prog=/usr/lib/cc-cfw/platform/ccragent/bin/ccccragent

case "$1" in
'start')
	echo "Starting ccragent"

	# make sure the watchdog program is there
	if [ ! -x $watchdog ] ; then
		echo "Not executable $watchdog"
		exit 1
	fi

	# start ccragent as a daemon process
	    $watchdog $prog 1 $pid_file &
	;;

'stop')
	echo "Stopping cccragent"

	# stop ccragent by killing its watchdog process
	if [ -f  $pid_file ] ; then
		kill -TERM `cat $pid_file` > /dev/null 2>&1
		sleep 10
		rm -f $pid_file
	fi
	;;

 *)
    echo "Usage : `basename $0` { start | stop }"
    ;;
esac

exit 0
