#!/bin/sh
#added by installer
Installpath=/data/Exceed_Connection_Server_13.7

# ####################################################################
# Exceed Connection Server 13.7
# Copyright (c) 1997-2009 Open Text Corporation. All Rights Reserved.
# ####################################################################
# ecsstart
# $Revision: 14686 $
# ####################################################################

# ecsstart script - start Exceed Connection Server 13.7
# arguments:
#	-q Quiet, don't produce output or ask questions
#	-r Clean, stop the server if running and clean up before starting

# some constants
VERSION="13.7"
SRV_NAME="Exceed Connection Server"
PROD_NAME="${SRV_NAME} ${VERSION}"

Banner="ecsstart - ${PROD_NAME}"
Usage1="Usage: ecsstart [-q] [-r]"
Usage2="    -q - Quiet, print no messages"
Usage3="    -r - Restart"
Usage4="         If ${SRV_NAME} is running, stop before starting."

CantRun1="Warning: Could not run necessary file: "
CantRun2="File may be corrupt or for another platform"
CantExecute="Warning: Could not execute necessary file: "
FileMissing="Warning: Could not find necessary file: "

CleanFileRel="/bin/ecsstop"
ClusterFileRel="/bin/sys/esessionmgr"
LibPathRel="/bin/sys/"
Executables="/bin/sys/ewebhost /bin/sys/authenticator /bin/sys/esessionmgr" 

if [ "x${Installpath}" =  "x" ] ; then
	Installpath="."
fi

# process the command line
Quiet="0"
Clean="0"
StartCM="0"
CoreDump="0"
for i
do
	case $i in
	-c)	CoreDump=1 ;;
	-q)	Quiet=1 ;;
	-r)	Clean=1 ;;
	-qr)	Quiet=1; Clean=1;;
	-rq)	Quiet=1; Clean=1;;
	*)	 echo ; echo ${Banner}; echo; echo ${Usage1}; echo "${Usage2}"; echo "${Usage3}"; echo "${Usage4}"; exit 1;;
	esac
done

# sanity check 
for i in ${Executables}
do
	fn="${Installpath}${i}"
	if [ -x "${fn}" ] ; then
		if  "$fn" --version > /dev/null 2>&1  ; then
			true
		else
			echo "${CantRun1} ${fn}"
			echo "${CantRun2}"
		fi
	else
		if [ -r "${fn}" ] ; then
			echo "${CantExecute} ${fn}"
		else
			echo "${FileMissing} ${fn}"
		fi
	fi
done

#create some file locations
CleanCmd="${Installpath}${CleanFileRel}"
ClusterCmd="${Installpath}${ClusterFileRel}"
LIBPATH="${Installpath}${LibPathRel}:${LIBPATH}"
export LIBPATH

#show the banner
if [ ${Quiet} != "1" ] ; then
	echo ""
	echo ${Banner}
	echo ""
	QuietArg=""
else
	QuietArg="-q"
fi

#clean, if necessary
if [ ${Clean} = "1" ] ; then
	${CleanCmd} ${QuietArg}
fi

#enable core dumps
if [ ${CoreDump} = "1" ] ; then
	ulimit -c unlimited
fi

#start the server
exec ${ClusterCmd} ${QuietArg} ${Installpath} &


