#!/bin/ksh
#
# Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#pragma ident	"@(#)start_sblsrvr.ksh	1.2	02/08/13 SMI"
#
#
# This script is used by the START method to start Siebel server.
#
# Input:
#
# - LHOSTNAME    - logical hostname configured for Siebel server
# - SIEBEL_ROOT  - location of Siebel server installation and siebenv.sh
#                  file (server_root)
# - SIEBEL_ENTERPRISE - Siebel enterprise name
# - SIEBSRVR_NAME - Siebel server name
#
# Return:
#
# 0 - Success
# 1 - Failure
#

PATH=$PATH:/usr/cluster/lib/sc
syslog_tag="SC[SUNW.sblsrvr,start_sblsrvr]"

if [ $# -ne 4 ]
then
	scds_syslog -p error -t $syslog_tag -m \
		"INTERNAL ERROR: usage: `basename $0` <logicalhost> <server_root> <siebel_enterprise> <siebel_servername>"
	exit 1
fi

export LHOSTNAME=$1
SERVER_ROOT=$2
SIEBEL_ENTERPRISE=$3
SIEBSRVR_NAME=$4

BASEPATH=`dirname $0`
BASEPATH=`dirname $BASEPATH`
BASEPATH=`dirname $BASEPATH`

. $SERVER_ROOT/siebenv.sh
rc=$?

if [ $rc -ne 0 ]
then
	scds_syslog -p error -t $syslog_tag -m \
		"Error while executing siebenv.sh."
	exit 1
fi

# There is no reliable method to verify if processes were started
# outside Sun Cluster control, or were leftover. Using list_server
# is not sufficient, since it uses PID to verify if the process is
# running. On another node, this PID could be an unrelated active
# process. srvrmgr requires gateway to be up. Therefore, all running
# Siebel server processes will be forced shutdown before a start is
# attempted. For manually starting Siebel server, users are required
# to disable the Sun Cluster Siebel server resource.

export LD_PRELOAD=$BASEPATH/lib/libloghost.so

# Using '-M' option will prevent reset_server from cleaning up shared
# memory resources created by another instance that may be up already,
# or may have just started.

reset_server -e $SIEBEL_ENTERPRISE -M $SIEBSRVR_NAME > /dev/null 2> /dev/null

start_server -e $SIEBEL_ENTERPRISE $SIEBSRVR_NAME > /dev/null 2> /dev/null
rc=$?

exit $rc
