#! /bin/sh
#set -x
#=========================================================================
# Copyright (C) GemTalk Systems 1986-2014.  All Rights Reserved..
#
# Name - gemnetobject.sh
#
# Purpose - Script to set environment and start a RPC gem.
#
# $Id: gemnetobject.sh 34104 2014-08-28 17:08:27Z normg $
#
#=========================================================================

if [ "a$GEMSTONE" = "a" ]; then
  echo "ERROR: GemStone scripts require a GEMSTONE environment variable."
  echo "       Please set it to the directory where GemStone resides."
  exit 1
fi

if [ "x$PATH" = "x" ]; then PATH=:/bin:/usr/bin:/usr/ucb; export PATH; fi 

# error control - do not allow hup
trap '' 1

comid="gemnetobject"			# this script's name
Syntax="Usage: gemnetobject TCP <socketFd> [ -h ] [ -T tocSizeKB]"
Hp="
        socketFD        - file descriptor of client socket inherited from fork
        tocSizeKb       - a command line option, overrides GEM_TEMPOBJ_CACHE_SIZE config"
Descript="
This Bourne shell script is invoked by a netldi to start a GemStone
session process, in response to a request of the netldi for a GemStone
session.  By default, the file $GEMSTONE/bin/services.dat translates the
GemStone service name gemnetobject to a command that executes this
script.  If no such translation is found, the command
\$HOME/gemnetobject is executed instead.

This script may  be  edited  to  change  the default gemname and/or gemdir
for custom gem executables.
"

# give a little help
if [ "x$1" = "xhelp" ] || [ "x$1" = "x-h" ] || [ "x$1" = "x-H" ]; then
  echo "$Syntax"; echo "$Hp"; echo "$Descript"; exit
fi

###########################################################################
################# User-definable symbols 
###########################################################################
gemname="gem"                   # name of the gem to execute
gemdir=""                       # directory where the gem lives
# GEMSTONE_SYS_CONF=""  # default is $GEMSTONE/data/system.conf
# GEMSTONE_EXE_CONF=""  # default is `pwd`/gem.conf
###########################################################################
#netldiSpec not set
#runpgsvrSpec not set
appName="$gemname"		# application name, for configuration

# determine gemname's location
if [ "$gemdir" = "" ]; then
  gemdir="$GEMSTONE/sys"
fi
if [ ! -f "$gemdir/$gemname" ]; then
  echo "${comid}[Error]:   cannot execute file $gemdir/$gemname"
  exit 1
fi

# show what we have

echo "${comId}[Info]:    the hostname is:  $hName"
echo "   GEMSTONE is:      \"${GEMSTONE}\""
echo "   ${gemname}'s location is: $gemdir"
echo "   system config file is:     $GEMSTONE_SYS_CONF"
echo "   executable config file is: $GEMSTONE_EXE_CONF"
echo "   ${gemname}'s arguments are: $* "

# The default behaviour is to delete this process's log file if it exits
# normally. If you want to keep this process's log file even on normal exit
# then uncomment the following
# export GEMSTONE_KEEP_LOG=1

# By default a gem will raise its number of descriptors to whatever the
# hard limit is. By setting GEMSTONE_MAX_FD to a positive number the
# gem will only raise its descriptors to that number.
# If GEMSTONE_MAX_FD is set to 0 then the gem will not modify its descriptor
# limit
# export GEMSTONE_MAX_FD=?

# Optional environment variables to increase the send and receive buffer sizes
# for the socket connecting the gem to its client.  The maximum values allowed
# are determined by the operating system.  Values that attempt to reduce the size
# of the buffers below the operating system defaults are ignored.
#
# export GS_SOCK_SEND_BUF_SIZE=?
# export GS_SOCK_RECV_BUF_SIZE=?

# Environment variable which turns on tracing of socket operations.  Enabling this
# variable will cause many extra messages to be printed to the gem log.
#
# export GEMSTONE_SOCKET_DEBUG=1

# start up gemname   
#  	sleep 3600 # enable for DEBUGGING
#       exit 0 # enable for DEBUGGING
exec "$gemdir/$gemname" $*
# with the above exec nothing after this is ever executed
