#! /usr/bin/sh
#
# ident	"@(#)cms_start.sh	1.27	99/02/02 SMI"
#
# Copyright (c) 1998 by Sun Microsystems, Inc.
# All rights reserved.
#
umask 022

PATH=$CMSHOME/lib:$CMSHOME/sbin:$CMSHOME/bin:$PATH
export PATH

# CMS home dir is now fixed.
CMSETC=/etc/SUNWcms
CMSVAR=/var/SUNWcms
export CMSETC CMSVAR

LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$CMSHOME/lib"
LD_LIBRARY_PATH=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

if [ ! -d $CMSETC/.locks ]
then
	mkdir -p $CMSETC/.locks
else
	rmdir $CMSETC/.locks/* 2>/dev/null
fi

if [ ! -d $CMSETC/.config ]
then
	mkdir -p $CMSETC/.config
fi

# wait for splitd
if [ -f $CMSHOME/lib/u4ftsplitd ]
then 
	if [ -f $CMSHOME/sbin/splitinfo ]
	then 
		ret_si=1
		for i in 1 2 4 6 8 10 12 14 16 18 20
		do
			if [ $ret_si -ne 0 ]
			then
        			sleep $i
        			splitinfo -d >/dev/null 2>&1
        			ret_si=$?
			fi
		done
	fi
fi

if [ ! -f $CMSETC/.config/configfile -a ! -f $CMSETC/.config/configfile- ]
then
	$CMSHOME/sbin/cmsinitialise
fi

$CMSHOME/lib/cmspohd -i
$CMSHOME/lib/cmsenvd

$CMSHOME/lib/cmsd

if [ $? = 0 ]
then
	$CMSHOME/lib/cmsmonitord
fi

$CMSHOME/lib/cmsfix start
