summaryrefslogtreecommitdiffstats
path: root/network/nessus/rc.nessusd
blob: a4a9c47376f057c5fc036530140141c6aed7fa65 (plain)
#!/bin/sh

# Tenable(TM) Nessus Scanner Start & Stop script
#

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
else
  exit 0
fi

# Load nessusd environment
[ -f /etc/sysconfig/nessusd ] && . /etc/sysconfig/nessusd

# Avoid using root's TMPDIR
unset TMPDIR

test -x /opt/nessus/sbin/nessus-service || {
  echo "Nessus not properly installed"
  exit 1
}

RETVAL=0

NESSUS_PID_FILE="/opt/nessus/var/nessus/nessus-service.pid"
NESSUS_NAME="Nessus"

start() {

  echo -n $"Starting Nessus services: "
  
  /opt/nessus/sbin/nessus-service -q -D
  RETVAL=$?

  if [ "$RETVAL" == "0" ]; then
    success
  else
    failure
  fi

  echo
  return 0

}

stop() {

  echo -n $"Shutting down Nessus services: "

  test -f "$NESSUS_PID_FILE" && kill `cat /opt/nessus/var/nessus/nessus-service.pid`
  RETVAL=$?
  
  sleep 4
  
  if [ "$RETVAL" == "0" ]; then
    success
  else
    failure
  fi
  
  echo
  return 0

}

restart() {
  stop
  start
}

status() {

  if [ -f "$NESSUS_PID_FILE" ]; then

    exp_pid=$(cat $NESSUS_PID_FILE)
    pid_dir="/proc/$exp_pid"
    
    if [ -d "$pid_dir" ]; then
      if [ "$(cat ${pid_dir}/stat | awk '{print $2}' | tr -d '()')" == "nessus-service" ]; then
        echo "$NESSUS_NAME is running"
        return 0
      fi
    fi

  fi

  echo "$NESSUS_NAME is not running"
  return 3

}


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

exit $?