#!/bin/bash  
#  
# Description:  This shell script takes care of starting and stopping dennis  
#  
# Source function library  

#the service name  for example: dennis  
SNAME=JYNGJCZ2

#the full path and name of the daemon program  
#Warning: The name of executable file must be identical with service name  
JYN_PATH=$(cd `dirname $0`;pwd)
PROG=$JYN_PATH/$SNAME
ZDFY=$JYN_PATH/filemonitor
#JEMALLOC1_PATH=$JYN_PATH/zav/libjemalloc.so.1
#JEMALLOC2_PATH=$JYN_PATH/zav/libjemalloc.so.2


# start function  
start() {  
#check the daemon status first  
	PID=`pidof $SNAME`
	if [ "$PID" = "" ] ; then
        if test -f $JEMALLOC1_PATH ; then
            export LD_PRELOAD=$JEMALLOC1_PATH
        elif test -f $JEMALLOC2_PATH ; then
            export LD_PRELOAD=$JEMALLOC2_PATH
        fi
		$PROG  
	else
		echo "$SNAME already running"
	fi

}  

#stop function  
stop() {  
	if [ -e $ZDFY ]; then
		$ZDFY stopSelfProtect
	fi
	
	PID=`pidof $SNAME`
	if [ "$PID" = "" ] ; then
		echo "$SNAME not running"
	else
		kill -9 `pidof $SNAME`
	fi

	if [ -e $ZDFY ]; then
		$ZDFY startSelfProtect
	fi
}  

case "$1" in  
start)  
start  
;;  
stop)  
stop  
;;  
reload|restart)  
stop  
start  
;;  
status)  
status $SNAME  
;;  
*)  
echo $"Usage: $0 {start|stop|restart|status}"  
exit 1  
esac  
