#!/bin/sh
#
# nessusd	This shell script takes care of starting and stopping
#		nessusd (Nessus security scanner Daemon).
#
# chkconfig: 345 85 15
# description: Nessus is a security auditing tool.
# processname: nessusd
# config: /etc/nessus/nessusd.conf

# Source function library.
. /etc/init.d/functions

# -a 127.0.0.1 : restricted to localhost, add it for restricted access
#OPTIONS="-a 127.0.0.1"
OPTIONS=""

RETVAL=0

prog="nessusd"

start() {
	echo -n $"Starting $prog: "
	if [ -r /var/nessus/CA/serverkey.pem ]; then
		daemon nessusd $OPTIONS -D
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/nessusd
		echo
	else
		echo -n " (you need to run nessus-mkcert first!)"
		echo_failure
		echo
		RETVAL=1
	fi
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc nessusd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/nessusd
	echo
	return $RETVAL
}

restart() {
	stop
	start
}

case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart)
	restart
	;;
condrestart)
	if [ -f /var/lock/subsys/nessusd ]; then
	    restart
	fi
	;;
status)
	status $prog
	;;
*)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL

