#! /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
VIRBOXLCCPATH=/opt/senseshield/virboxlcc
N=/etc/init.d/virboxlccd
export PATH="$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

#set -e
if [ -r $VIRBOXLCCPATH ]
then
	case "$1" in
	  start)
      
        # ĬջռСӰ VirboxLCC ռڴ棬1024KB(1MBwindowsһ)ʱռڴ28MB
        ulimit -s 1024
        
		$VIRBOXLCCPATH > /etc/null &
		;;
	  stop)
      
        sleep 5
        
		ret=`ps -ef|grep "$VIRBOXLCCPATH" |grep -v "grep"`
        ret2=`ps|grep "$VIRBOXLCCPATH" |grep -v "grep"`     # ݲͬ汾ARMϵͳARMϵͳ ps ֲ֧
		if [ x"$ret" != x -o x"$ret2" != x ]    # -o(or), -a(and)
		then
			kill -9 $(pidof virboxlcc)
			sleep 5
		fi
		;;
	  restart)
	
		ret=`ps -ef|grep "$VIRBOXLCCPATH" |grep -v "grep"`
        ret2=`ps|grep "$VIRBOXLCCPATH" |grep -v "grep"`
        if [ x"$ret" != x -o x"$ret2" != x ]
        then
            kill -9 $(pidof virboxlcc)
        fi
		sleep 5
		$VIRBOXLCCPATH > /etc/null &
		;;
	  status)
		ret=`ps -ef|grep "$VIRBOXLCCPATH" |grep -v "grep"`
        ret2=`ps|grep "$VIRBOXLCCPATH" |grep -v "grep"`
		if [ x"$ret" = x -a x"$ret2" = x ]
		then
			echo "VirboxLCC stop"
		else
			echo "VirboxLCC 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
