#!/sbin/sh
#
# ident	"@(#)init.wbem.sh	1.59	03/05/09 SMI"
#
# Copyright 2000-2003 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

if [ -x /usr/sadm/lib/smc/bin/smcboot ]; then
	VIPER_HOME=/usr/sadm/lib/smc
	export VIPER_HOME

	SMC_PORT=`getent services ftp | cut -d' ' -f1`
	if [ -n "$SMC_PORT" ]; then
		SMC_PORT=898
	fi
fi

case "$1" in
'start')
	if [ -n "$VIPER_HOME" ]; then
		$VIPER_HOME/bin/smcboot >/dev/msglog 2>&1 &
	else
		umask 066; /usr/sadm/lib/wbem/cimomboot "$@" >/dev/msglog 2>&1 &
		echo $! >/var/sadm/wbem/logr/cimbootserver.pid
	fi
	;;

'stop')
	if [ -n "$VIPER_HOME" ]; then
		if [ -f /tmp/smc$SMC_PORT/boot.pid ]; then
			kill -TERM `cat /tmp/smc$SMC_PORT/boot.pid`
		else
			$VIPER_HOME/bin/smcserver -p $SMC_PORT stop
		fi
	else
		for daemon in cimbootserver cimomserver ; do
			pidfile=/var/sadm/wbem/logr/$daemon.pid
			if [ -f $pidfile ]; then
				pid=`/usr/bin/cat $pidfile`
				[ "$pid" -gt 0 ] && kill $pid >/dev/null 2>&1
				rm -f $pidfile
			fi
		done
	fi
	;;

status)
	if [ -n "$VIPER_HOME" ]; then
		$VIPER_HOME/bin/smcserver -p $SMC_PORT status
	fi
	;;

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