#! /bin/sh
#set -x
#=========================================================================
# Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved..
#
# Name - runpgsvr.sh
#
# Purpose - 
#
#	It is expressly permitted to make a copy of this file in some
#	other directory than $GEMSTONE/sys; hence help logic
#	is different here.
#
# $Id: runpgsvr.sh,v 1.7 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

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

Syntax="Usage: runpgsvr <protocol> <wellknown> <timeout>
OR runpgsvr   <monName> <numPages> <numProcs> <memLock> <spinLockCount>
              <targetFreeFrames> <numFreeFrameServers> <numSharedCounters>
              <protocol> <wellknown> <timeout>
OR   runpgsvr -h|-H|help

      monName - name of shared page cache monitor to create
      numPages - number of memory pages for monitor
      numProcs - number of process slots for monitor
      memLock - true if monitor's memory should be locked in place
      spinLockCount - spin count for shared locks
      targetFreeFrames - set the target free frame limit for the cache
      numFreeFrameServers - number of free frame servers to start
      numSharedCounters - number of shared counters to create
      protocol  - network protocol for connection, such as \"TCP\"
      wellknown - bound network address, such as a TCP/IP port number
      timeout   - how long, in seconds, to wait for connection

This Bourne shell script is invoked by a netldi in reponse to a
request of the netldi to provide GemStone database file I/O. By
default, netldi uses the file $GEMSTONE/bin/services.dat to translate the
name runpgsvr to a command that executes this script.  If no such
translation is found, the command \$HOME/runpgsvr is executed by
netldi instead.
"

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

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

# pgsvr is required
if [ ! -x $GEMSTONE/sys/pgsvr ]; then
  echo "${comid}[Error]:   cannot find file $GEMSTONE/sys/pgsvr"
  exit 1 
fi

# show what we have
echo "runpgsvr[Info]:     Description of arguments:"
hName=`/bin/uname -n`
echo "   the hostname is:     $hName"
echo "   GEMSTONE is:         $GEMSTONE"
echo "   pgsvr 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
# PgsvrTraceMode=1
# export PgsvrTraceMode

# start pgsvr - pgsvr needs GEMSTONE

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

if [ "$#" = "11"  ]; then
  # start a monitor ignore timeout(arg11)
  exec $GEMSTONE/sys/pgsvr "'"$1"'" setlocationstr $2 setnumpages \
  $3 setnumprocs $4 setmemlock $5 setspinlockcount \
  $6 settargetfflimit $7 setnumffservers $8 setnumsharedctrs \
  "'"$9"'" setprotocol "'"$10"'" setwks \
  startup attach sloop exit
  # "trace" may be added prior to "sloop" 
else
  # start an ordinary server; ignore timeout(arg3)
  exec $GEMSTONE/sys/pgsvr "'"$1"'" setprotocol "'"$2"'" setwks startup sloop exit
  # "trace" may be added prior to "sloop" 
fi
# with the above exec nothing after this is ever executed
