#! /bin/sh
#set -x
#=========================================================================
# Copyright (C) GemTalk Systems 1986-2024.  All Rights Reserved.
#
# Name - runstatmonitor.sh
#
# Purpose - script to set environment and start statmonitor
#
#=========================================================================

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 
					
comid="runstatmonitor"

Syntax="Usage: ${comid} <args>"

# 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

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

# show what we have
echo "${comid}[Info]:     Description of arguments:"
# bug 40199 - determine correct location for uname
if [ -f "/bin/uname" ]; then
  UNAME="/bin/uname"
elif [ -f "/usr/bin/uname" ]; then
  UNAME="/usr/bin/uname"
else
# Weird case.  Let's just hope it's in the path...
  UNAME="uname"
fi
hName=`$UNAME -n`

# 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
# GEMSTONE_KEEP_LOG=1 ; export GEMSTONE_KEEP_LOG

echo "   the hostname is:           $hName"
echo "   GEMSTONE is:               $GEMSTONE"
echo "   statmonitor arguments are: $*"

# start a statmonitor
exec "$GEMSTONE/bin/statmonitor" "$@"
# with the above exec nothing after this is ever executed
