#!/bin/sh
#
# chkconfig: 3 90 08
# description: ProScan Enterprise for IBM
### BEGIN INIT INFO
# Provides: proscan
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 3
# Default-Stop: 0 1 2 5 6
# Description: Start the ProScan antivirus engin daemon
### END INIT INFO
PROSCAN_BIN=/opt/proscan/bin/proscan
CLAMAV_DIR=/usr/lib/clamav

subsys_start() {
    ##add_start
    #CHK=`lsmod|grep dazuko`
    #if [ "$CHK" = "" ]
    #then
    #    /opt/proscan/contrib/dazuko_mod start
    #fi
    ## oas
    #OAS=`ps ax|grep bin/proscanoas|grep -v grep`
    #if [ "$OAS" = "" ]
    #then
    #    /opt/proscan/bin/proscanoas
    #fi
    true
}

subsys_stop() {
    ##add_stop
    #OAS=`ps ax|grep bin/proscanoas|grep -v grep|awk '{print $1}'`
    #if [ "$OAS" != "" ]
    #then
    #    kill $OAS
    #fi
    #CHK=`lsmod|grep dazuko`
    #if [ "$CHK" != "" ]
    #then
    #    /opt/proscan/contrib/dazuko_mod stop
    #fi
    true
}

start() {
  if [ -x $PROSCAN_BIN ]; then
      ldconfig $CLAMAV_DIR
      $PROSCAN_BIN > /dev/null 2>&1
       if [ $? -eq 0 ]; then
          echo "ProScan was started"
          subsys_start
        else 
          echo "ProScan couldn't be started"
      fi
  else 
      echo "$PROSCAN_BIN was not found"
      exit 2
  fi  
  
}
stop() {
  subsys_stop
  if [ -x $PROSCAN_BIN ]; then
      $PROSCAN_BIN stop  > /dev/null 2>&1
      if [ $? -eq 0 ]; then
          echo "ProScan was stoped"
          return 0
      else
          echo "ProScan couldn't be stoped" 
      fi
  else 
      echo "$PROSCAN_BIN was not found"
      exit 2
  fi  
}

status() {
  PS=`ps ax |grep $CLAMAV_DIR/clamd |grep -v grep`
  if [ -n "$PS" ]; then 
      echo "ProScan is running"
      exit 0
    else
      echo "ProScan is not running"
      exit 1
  fi
}

restart() {
  stop
  sleep 1
  start
}

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

exit 0
