#! /bin/sh
#set -x
#=========================================================================
# Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved..
#
# Name - rungcgem.sh
#
# Purpose - Script to run page manager, admin, symbol creation, and reclaim
#           gems.
#
# $Id: rungcgem.sh,v 1.6 2008-01-09 22:50:53 stever Exp $
#
#=========================================================================

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

# echo $LD_LIBRARY_PATH
LD_LIBRARY_PATH=$GEMSTONE/lib
export LD_LIBRARY_PATH

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

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

comid="rungcgem"			# this script's name

Syntax="Usage: $comid gemCommand gemStoneName args "
Hp="       gemStoneName    - the name of the stone"

Descript="
This Bourne shell script is invoked by a netldi or stone to start a GemStone
Admin, Reclaim or Symbol Creation   Gem process.
By default, the file $GEMSTONE/bin/services.dat translates the GemStone service
name $comid to a command that executes this script.  If no such translation 
is found, the command \$HOME/$comid is executed instead.
"

# 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
systemConfig=""                 # GEMSTONE_SYS_CONF


if [ "$1" = "reclaimgcgem" ]; then
  exeConfig=""  # path for custom GEMSTONE_EXE_CONF for reclaimgc gems
else
if [ "$1" = "admingcgem" ]; then
  exeConfig=""  # path for custom GEMSTONE_EXE_CONF for admingc gem
else
if [ "$1" = "symbolgem" ]; then
  exeConfig=""  # path for custom GEMSTONE_EXE_CONF for symbol creation gem
else
if [ "$1" = "pagemanager" ]; then
  exeConfig=""  # path for custom GEMSTONE_EXE_CONF for page manager gem
fi
fi
fi
fi

###########################################################################
#netldiSpec not set
#runpgsvrSpec not set
appName="GcGem"  		# application name, for configuration

###########################################################################
################# User-Changeable Option 
###########################################################################

# Misc support...
. $GEMSTONE/bin/misc.sh

# set configuration args
. $GEMSTONE/bin/setconfig.sh

# determine gemname's location
if [ "$gemdir" = "" ]; then
  gemdir=$GEMSTONE/sys
fi
requireExes $gemdir/$gemname

gemStoneName=$2
# we must have a gemStoneName
if [ "x$gemStoneName" = "x" ]; then 
   if ( test -t ); then
      echo "enter _gemStoneName: " stopstone.getgsname
      read gemStoneName
   fi
   if [ "x$gemStoneName" = "x" ]; then 
      # no gemStoneName given
      echo "stopstone[Error]: you must specify the gemStoneName."
      exit 1
   fi
fi

# show what we have
hName=`/bin/uname -n`
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 unset GEMSTONE_CHILD_LOG.
#unset GEMSTONE_CHILD_LOG

# 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=?

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