#!/sbin/sh
#
# Copyright 1999-2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)slpd	1.3	03/05/21 SMI"

CONF=/etc/inet/slp.conf
JAVA_BIN=/usr/j2se/bin/java
CLASSPATH=/usr/share/lib/slp/slpd.jar
MAIN_CLASS=com.sun.slp.slpd
SLPD_HOME=/usr/lib/inet
SLPD=slpd
SLPD_BIN=$SLPD_HOME/$SLPD

case "$1" in
'start')
	# If a configuration file exists start the slpd proxy.
	[ -f $CONF ] && $SLPD_BIN -f $CONF >/dev/msglog 2>&1 &
	;;

'stop')
	# Kill the slpd proxy.
	/usr/bin/pkill -x -u 0 -P 1 $SLPD

	# If a configuration file exists signal a shutdown to the real slpd.
	[ -f $CONF  ] && {
		$JAVA_BIN -classpath $CLASSPATH \
			$MAIN_CLASS stop -f $CONF >/dev/msglog 2>&1 &

		(
			# Give the above slpd instance a chance to signal
			# a shutdown to the real slpd instance. If after
			# this time it has hung kill it.
			sleep 5

			# The pattern must not exceed 80 chars!
			/usr/bin/pkill -x -f -u 0 -P 1,$$ \
				"${JAVA_BIN}.*-classpath ${CLASSPATH} .*"
		) &
	}
	;;
*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit 0
