#!/bin/sh
#
# Copyright 1998 Sun Microsystems, Inc. All Rights Reserved
#
# @(#)ssadmserver.sh	1.2 98/12/14 Sun Microsystems, Inc.
#

SSDIR=/opt/SUNWicg/SunScreen
pidfile=/var${SSDIR}/ssadmserver.pid

: ${JAVA_HOME=/usr/java}
PATH="${JAVA_HOME}/bin:/usr/bin"
CLASSPATH="${SSDIR}/admin"
export PATH CLASSPATH

start_daemon() {
    sh -c 'echo $$'" >$pidfile
	   exec java com.sun.sunscreen.internal.ssadm.Server $@" &
}

kill_daemon() {
    [ -r $pidfile ] && read pid <$pidfile && kill $pid
}

case "$1" in
'start')
	shift
	if [ -r $pidfile ] &&
	   read pid <$pidfile &&
	   kill -0 $pid >/dev/null 2>&1
	then echo "SunScreen Admin Server already running, process $pid."
	     exit 1
	else start_daemon ${1+"$@"}
	fi
	;;

'stop')
	if kill_daemon
	then echo "SunScreen Admin Server Stopped."
	     /bin/rm $pidfile
	#else echo "Warning: SunScreen Admin Server was not running."
	fi
	;;

'status')
	if [ -r $pidfile ] &&
	   read pid <$pidfile &&
	   kill -0 $pid >/dev/null 2>&1
	then echo "SunScreen Admin Server running, process $pid."
	else echo "SunScreen Admin Server not running."
	fi
	;;

*)
	echo>&2 "Usage: ssadmserver { start | stop | status }"
	exit 1
	;;

esac
