#! /bin/sh
#set -xv
#=========================================================================
# Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved..
#
# Name - startshrpcmon.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: startshrpcmon.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
fi

# default PATH
if [ "x$PATH" = "x" ]; then PATH=:/bin:/usr/bin:/usr/ucb; export PATH; fi 
					
. $GEMSTONE/bin/misc.sh

comid="startshrpcmon"

Syntax="Usage: startshrpcmon <monitorname> <numpages> <numprocs> <memlock> <spinlockcount> <targetfflimit> <numFFpgsvrs> <numSharedCtrs> [-h]

        monitorname     - monitor name (usually stone name & hostId)
        numpages        - number of pages to allocate for the shared cache
        numprocs        - max number of processes that need to attach to it
        spinlockcount   - number trys to get lock before sleeping on semaphore
	memlock         - (boolean) whether to lock the cache in memory
        targetfflimit   - target free frame limit
        numFFpgsvrs     - number of free frame page servers to start
        numSharedCtrs   - number of shared counters for this shared cache

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

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

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

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

# show what we have
# say shrpcmon.summary "`/bin/uname -n`" $GEMSTONE $1 $2 $3 $4 $5 $6 $7
hName=`/bin/uname -n`
echo "SharedPageCache Monitor Summary:"
echo "   the hostname is:    $hName"
echo "   GEMSTONE is:        \"${GEMSTONE}\""
echo "   shrpcmon arguments are:" 
echo "      SharedPageCache Monitor name  $1."
echo "      Number of pages               $2."
echo "      Number of processes           $3."
echo "      Cache locked in memory        $4."
echo "      SpinLockCount                 $5."
echo "      TargetFreeFrameCount          $6."
echo "      Number of free frame servers  $7."
echo "      Number of shared counters     $8."

# 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
raiseDescriptors   
# start shrpcmon - shrpcmon needs GEMSTONE
exec $GEMSTONE/sys/shrpcmonitor "'"$1"'" setlocationstr $2 setnumpages \
  $3 setnumprocs $4 setmemlock $5 setspinlockcount $6 settargetfflimit \
  $7 setnumffpgsvrs $8 setnumsharedctrs startup sloop exit
# with the above exec nothing after this is ever executed
