#!/bin/sh
#
# easyagent-tcp		easyAGENT startup script
#
# chkconfig: 345 50 80
# description: This is a observer monitoring system agent
# processname: easyagent

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

start() {
	if [ -x /usr/local/soap/bin/easyagent ]; then
		echo -n "Starting easyAGENT: "
		daemon su easyagnt -c /usr/local/soap/bin/easyagent.sh
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/easyagent-tcp
	fi
	echo
	return $RETVAL
}

stop() {
	echo -n "Shutting down easyAGENT: "
	if [ -f /usr/local/soap/log/easyagent.pid ]; then
		kill `cat /usr/local/soap/log/easyagent.pid`
		RETVAL=$?
		[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/easyagent-tcp
	fi
	echo
	return $RETVAL
}

restart() {
	echo -n "Sending easyAGENT a restart signal: "
	if [ -f /usr/local/soap/log/easyagent.pid ]; then
		kill -HUP `cat /usr/local/soap/log/easyagent.pid`
		RETVAL=$?
	fi
	echo
	return $RETVAL
}

RETVAL=0

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	restart
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload}"
	exit 1
	;;
esac

exit $?
