47c3930
#!/bin/bash
47c3930
47c3930
# This is an implementation of a start-script for OpenVAS Scanner.
47c3930
47c3930
# Make RedHat happy:
47c3930
#
47c3930
# chkconfig: - 91 9
47c3930
# Description: OpenVAS is a vulnerability Scanner
47c3930
#
47c3930
47c3930
### BEGIN INIT INFO
47c3930
# Provides: openvas-scanner
47c3930
# Required-Start: $local_fs $network $syslog
47c3930
# Required-Stop: $local_fs $network $syslog
47c3930
# Default-Start:
47c3930
# Default-Stop: 0 1 2 3 4 5 6
47c3930
# Short-Description: start|stop|status|restart|condrestart|reloadplugins OpenVAS Scanner
47c3930
# Description: control OpenVAS Scanner
47c3930
### END INIT INFO
47c3930
47c3930
# Source function library.
47c3930
. /etc/rc.d/init.d/functions
47c3930
47c3930
exec="/usr/sbin/openvassd"
47c3930
prog="openvassd"
47c3930
progname="openvas-scanner"
47c3930
config=/etc/openvas/openvassd.conf
47c3930
lockfile=/var/lock/subsys/openvas-scanner
47c3930
47c3930
[ -e /etc/sysconfig/$progname ] && . /etc/sysconfig/$progname
47c3930
8d44341
47c3930
rh_status() {
47c3930
	# run checks to determine if the service is running or use generic status
Stjepan Gros d2acf37
	status -p /var/run/$prog.pid $progname
47c3930
}
47c3930
47c3930
rh_status_q() {
47c3930
	rh_status >/dev/null 2>&1
47c3930
}
47c3930
47c3930
start() {
8d44341
8d44341
	# Build parameters
40aa2ff
	[ -n "$SCANNER_LISTEN" ] && PARAMS="$PARAMS $SCANNER_LISTEN"
40aa2ff
	[ -n "$SCANNER_PORT" ]   && PARAMS="$PARAMS $SCANNER_PORT"
40aa2ff
	[ -n "$SCANNER_SRCIP" ]  && PARAMS="$PARAMS $SCANNER_SRCIP"
8d44341
Stjepan Gros d2acf37
	grep -q ca_file $config >& /dev/null
47c3930
	if [ $? -ne 0 ]; then
6ba7663
		logger --tag "$progname" "No certificate specified in configuration file. Did you run openvas-mkcert tool?"
1787dcc
		exit 2
47c3930
	fi
47c3930
Stjepan Gros d2acf37
	CACERT=`grep ca_file $config | cut -d= -f2`
47c3930
	if [ \! -z "$CACERT" -a \! -f "$CACERT" ]; then
092200e
		logger --tag "$progname" "CA Certificate specified in the configuration file not found. Did you run openvas-mkcert tool?"
1787dcc
		exit 2
47c3930
	fi
47c3930
092200e
	KEYFILE=`grep key_file $config | cut -d= -f2`
092200e
	if [ \! -z "$KEYFILE" -a \! -f "$KEYFILE" ]; then
092200e
		logger --tag "$progname" "Private key specified in the configuration file not found. Did you run openvas-mkcert tool?"
092200e
		exit 2
092200e
	fi
092200e
092200e
	CERTFILE=`grep cert_file $config | cut -d= -f2`
092200e
	if [ \! -z "$CERTFILE" -a \! -f "$CERTFILE" ]; then
092200e
		logger --tag "$progname" "Public Certificate specified in the configuration file not found. Did you run openvas-mkcert tool?"
092200e
		exit 2
092200e
	fi
092200e
092200e
47c3930
	echo "Starting $progname:"
8d44341
	daemon --pidfile=/var/run/$prog.pid $prog -q $PARAMS
47c3930
	RETVAL=$?
47c3930
	echo
47c3930
	[ $RETVAL -eq 0 ] && touch $lockfile
47c3930
	return $RETVAL
47c3930
}
47c3930
47c3930
stop() {
47c3930
	echo -n "Stopping $progname: "
47c3930
	killproc $prog
47c3930
	RETVAL=$?
47c3930
	echo
47c3930
	[ $RETVAL -eq 0 ] && rm -f $lockfile
47c3930
	return $RETVAL
47c3930
}
47c3930
47c3930
restart() {
47c3930
	stop
47c3930
	start
47c3930
}
47c3930
47c3930
reloadplugins() {
47c3930
	echo -n "Reloading OpenVAS plugins: "
47c3930
	killproc $prog -HUP
47c3930
	echo
47c3930
}
47c3930
47c3930
case "$1" in
47c3930
	start)
47c3930
		rh_status_q && exit 0
47c3930
		$1
47c3930
		;;
47c3930
47c3930
	stop)
47c3930
		rh_status_q || exit 0
47c3930
		$1
47c3930
                ;;
47c3930
47c3930
	restart)
47c3930
		$1
47c3930
		;;
47c3930
47c3930
	condrestart|try-restart)
47c3930
		rh_status_q || exit 0
47c3930
		$1
47c3930
		;;
47c3930
47c3930
	reload)
47c3930
		;;
47c3930
47c3930
	reloadplugins)
47c3930
		rh_status_q || exit 0
47c3930
		$1
47c3930
		;;
47c3930
47c3930
	status)
Stjepan Gros d2acf37
		status -p /var/run/$prog.pid $progname
47c3930
                ;;
47c3930
47c3930
	*)
47c3930
		echo "Usage: $0 {start|stop|status|restart|condrestart|reload|reloadplugins}"
47c3930
		exit 1
47c3930
esac
47c3930
47c3930
exit 0