#!/bin/sh
#
# chkconfig: 3 90 08
# description: ProScan for IBM Power Systems(Linux)
### BEGIN INIT INFO
# Provides: proscan_onaccess
# Required-Start: $proscan
# Required-Stop: $proscan
# Default-Start: 3
# Default-Stop: 0 1 2 5 6
# Description: Start the ProScan onAccess scan daemon
### END INIT INFO

PROSCAN_BIN=/opt/proscan/bin/proscan
OAS_BIN=/opt/proscan/bin/proscanoas

start() {
    if [ -x $OAS_BIN ]; then
        $OAS_BIN > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            echo "ProScan on access scanner was started"
        else
            echo "ProScan OAS couldn't be started"
        fi
    fi
}

stop() {
    killall proscanoas
}

status() {
  PS=`ps ax |grep $OAS_BIN |grep -v grep`
  if [ -n "$PS" ]; then
      echo "ProScan OnAccess Scanner is running"
      exit 1
    else
      echo "ProScan OnAccess Scanner is not running"
      exit 0
  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
