#!/bin/bash  
#  
# JYNGJCZ 
# chkconfig: 2345 99 01
# description: jingyunsd service, dealing with the virus

### BEGIN INIT INFO
# Provides:          JYNGJCZ
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: jingyunsd service
# Description:       jingyunsd service, dealing with the virus
### END INIT INFO  

SNAME=JYNGJCZ2
JYN_PATH=/opt/apps/vrvsd-tl
PROG=$JYN_PATH/JYNGJCZ1  
ZDFY=$JYN_PATH/filemonitor

is_protect()
{
	selfProtect=`cat $JYN_PATH/Config.ini|grep "SelfProtect"`
    echo ${selfProtect:14:1}
}

stop_self_protect()
{
	if [ -f $ZDFY ]; then
		$ZDFY stopSelfProtect
	fi
}

start_self_protect()
{
	if [ "$(is_protect)"e != "0"e ] ; then
		if [ -f $ZDFY ]; then
			$ZDFY startSelfProtect
		fi
	fi
}

start() {  
#check the daemon status first  
	PID=`pidof $SNAME`
	if [ "$PID" = "" ] ; then
		$PROG start
		echo "start $SNAME"
	else
		echo "$SNAME already running"
	fi
}  

stop() {  
	stop_self_protect
	PID=`pidof $SNAME`
	if [ "$PID" = "" ] ; then
		echo "$SNAME not running"
	else
		kill -9 `pidof $SNAME`
	fi
	start_self_protect
}  

status(){
	PID=`pidof $SNAME`
	if [ "$PID" = "" ] ; then
		echo "$SNAME not running"
	else
		echo "$SNAME is running"
	fi
}

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