#! /bin/sh

### BEGIN INIT INFO
# Provides:         
# Required-Start:    
# Required-Stop:
# X-Start-Before:    
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: 
# Description: 
### END INIT INFO
SENSEPATH=/opt/senseshield/senseshield
N=/etc/init.d/senseshieldd
export PATH="$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

#set -e
if [ -r $SENSEPATH ]
then
	case "$1" in
	  start)
		# /opt/senseshield/extra.sh addport
        
        # ĬջռСӰ senseshield ռڴ棬1024KB(1MBwindowsһ)ʱռڴ28MB
        ulimit -s 1024
        
		$SENSEPATH
		;;
	  stop)
		
		ret=`ps -ef|grep "$SENSEPATH" |grep -v "grep"`
        ret2=`ps|grep "$SENSEPATH" |grep -v "grep"`     # ݲͬ汾ARMϵͳARMϵͳ ps ֲ֧
		if [ x"$ret" != x -o x"$ret2" != x ]    # -o(or), -a(and)
		then
			kill -9 $(pidof senseshield)
			sleep 5
			# /opt/senseshield/extra.sh delport
		fi
		;;
	  restart)
	
		ret=`ps -ef|grep "$SENSEPATH" |grep -v "grep"`
        ret2=`ps|grep "$SENSEPATH" |grep -v "grep"`
        if [ x"$ret" != x -o x"$ret2" != x ]
        then
            kill -9 $(pidof senseshield)
        fi
		sleep 5
		# /opt/senseshield/extra.sh delport
		# /opt/senseshield/extra.sh addport
		$SENSEPATH
		;;
	  status)
		ret=`ps -ef|grep "$SENSEPATH" |grep -v "grep"`
        ret2=`ps|grep "$SENSEPATH" |grep -v "grep"`
		if [ x"$ret" = x -a x"$ret2" = x ]
		then
			echo "senseshield stop"
		else
			echo "senseshield start/running"
		fi
		;;
	  *)
		echo "Usage: $N {start|stop|restart|status}" >&2
		exit 1
		;;
	esac
else
	echo "Warning: the exec does not exist or you do not have sufficient permissions"
fi

exit 0
