#!/bin/bash

cmd=`basename $0`

usage()
{
  echo "usage: $cmd start | stop"
  exit 0
}

if [ "$1" = "" ]
then
   usage
fi

export PATH=$PATH:/opt/IBMJava/jre/bin

CLASSPATH=/usr/websm/codebase/pluginjars/aca.jar:/usr/websm/codebase/pluginjars/ccfw.jar:/usr/websm/codebase/pluginjars/sniacimom.jar:/usr/websm/codebase/pluginjars/hsc.jar:/usr/websm/codebase/pluginjars/hsc_bundles.jar:$CLASSPATH
export CLASSPATH
PATH=$JAVAPATH:/opt/hsc/bin:$PATH
export PATH
FILESVRID=/tmp/fileserver.pid


case $1 in
start )
    STOP_PID=`ps -efwww | grep FsServer | grep -v grep | cut -c10-15`
    if [ "$STOP_PID" == "" ]
    then
       java com.ibm.hsc.filesvr.FsServer &
       pid=$!

      echo $pid > $FILESVRID
      /bin/chmod 0440 $FILESVRID
      echo "File Server (PID=$pid) started"
    fi
    ;;

stop )
   if [ -f $FILESVRID ]; then
      pid=`cat $FILESVRID`
      
      kill -15 $pid >/dev/null 2>&1
      rm -f $FILESVRID
      echo "File Server (PID=$pid) stopped"
   fi
   STOP_PID=`ps -efwww | grep FsServer | grep -v grep | cut -c10-15`
   if [ "$STOP_PID" != "" ]
   then
       echo Stopping File Server
       kill -9 $STOP_PID >/dev/null 2>&1
   fi

   ;;
esac
