#!/bin/sh
# @(#)lmxsvc.sh	1.3	5/24/96

PCNL_INSTANCE=$1
export PCNL_INSTANCE
IDIR=$2
export IDIR

LMPATHS="`/bin/dirname $0`/../lib/lmpaths"

if [ -f ${LMPATHS} ]
then
    . ${LMPATHS}
else
    . lmpaths
fi

# INFORMATION
# This command is run by lmx.ctrl pretty late in initialization -- just
# before the LAN Manager/X server is fully ready to go.  The job of this
# script is to start any adjunct services that go with the server.
# This command is run from the LAN Manager home directory, and its output
# is appended to lmxstart.log.

PATH=:$PATH
export PATH

(
	echo "\n$LMXSVC_NAME: Starting service processes at `date`"

	TIMEX_IT=`${SRVCONFIG_PATH} -I $PCNL_INSTANCE -g "lmxserver,timex"`

	echo "\n\tThe environment contains the following strings:"
	env | while read STRING
	do
		echo "\t$STRING"
	done
	echo "\n"

	if [ -d $SERVICE_PATH ]
	then
		cd $SERVICE_PATH

		if [ -x $LMXDMN_NAME ]
		then
			echo "\tStart $LMXDMN_NAME at \c"; date
			if [ ${TIMEX_IT} -ne 0 ]
			then
				$TIMEX_PATH -s $LMXDMN_NAME -I $PCNL_INSTANCE > $DEV_NULL_PATH \
					2> ${TIMEXDIR_PATH}/${LMXDMN_NAME}
			else
				$LMXDMN_NAME -I $PCNL_INSTANCE > $DEV_NULL_PATH 2>&1 < $DEV_NULL_PATH
			fi
			if [ $? != 0 ]
			then
				echo "\t\t$LMXDMN_NAME exit code $? at \c"; date
			fi
		fi

		for i in *
		do
			if [ $i != "$LMXDMN_NAME" -a -x $i ]
			then
				$STARTSVC_PATH $i -I $PCNL_INSTANCE
				if [ $? != 0 ]
				then
					continue
				fi
				echo "\tStart $i at \c"; date
				if [ ${TIMEX_IT} -ne 0 ]
				then
					NAME=`basename ${i}`
					$TIMEX_PATH -s $i -I $PCNL_INSTANCE > $DEV_NULL_PATH \
						2> ${TIMEXDIR_PATH}/${NAME}
				else
					$i -I $PCNL_INSTANCE > $DEV_NULL_PATH 2>&1 < $DEV_NULL_PATH
				fi
				if [ $? != 0 ]
				then
					echo "\t\t$i exit code $? at \c"; date
				fi
			fi
		done

	else
		echo "\tNo $SERVICE_PATH directory.\nNo services started."
	fi
	echo "\n$LMXSVC_NAME: Completed at `date`"

) >> $START_LOG_PATH 2>&1
