File rcntop of Package ntop

#! /bin/sh
# Copyright (c) 1995-2011 SUSE Linux Products GmbH
#
# Author: Remo Behn <ray@suse.de>
#         Lars Vogdt <lrupp@suse.de>
#
# /etc/init.d/ntop
# and its symbolic link
# /usr/sbin/rcntop
#
### BEGIN INIT INFO
# Provides: 		ntop
# Required-Start: 	$network $remote_fs
# Should-Start:     cron $time
# Required-Stop: 	$network
# Should-Stop:      $time
# Default-Start: 	3 5
# Default-Stop: 	0 1 2 6
# Short-Description: ntop Network Monitor
# Description: Tool for monitoring the network usage.
### END INIT INFO

PROGRAM='/usr/bin/ntop'
test -x "$PROGRAM" || { echo "$PROGRAM not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

CONFFILE='/etc/sysconfig/ntop'
test -r "$CONFFILE" || { echo "$CONFFILE not existing";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

. $CONFFILE
. /etc/rc.status

function setup_options()
{
	# use default options
	NTOP_OPTIONS="-P /var/lib/ntop"
	# define the NTOP_IFACE
	if [ -n "$NTOPD_IFACE" ]; then
		NTOP_OPTIONS="$NTOP_OPTIONS -i $NTOPD_IFACE"
	else
		rc_failed 6
		rc_status -v
		exit 6
	fi
	# setup the user to run ntop
	if [ -n "$NTOP_USER" ]; then
		NTOP_OPTIONS="$NTOP_OPTIONS -u $NTOP_USER"
	else
		rc_failed 6
		rc_status -v
		exit 6
	fi
	# setup port
	if [ -n "$NTOPD_PORT" -o -n "$NTOPD_SSL_PORT" ]; then
		if [ -n "$NTOPD_PORT" ]; then
			NTOP_OPTIONS="$NTOP_OPTIONS -w $NTOPD_PORT"
		fi
		if [ -n "$NTOPD_SSL_PORT" ]; then
			NTOP_OPTIONS="$NTOP_OPTIONS -W $NTOPD_SSL_PORT"
		fi
	else
            rc_failed 6
            rc_status -v
            exit 6
        fi
	# use optional
	test -n "${NTOP_ARGS}" && NTOP_OPTIONS="${NTOP_OPTIONS} ${NTOP_ARGS}"
}

# Reset status of this service
rc_reset

# The echo return value for success (defined in /etc/rc.config).
case "$1" in
    start)
		echo -n "Starting service ntop "
		if checkproc /usr/bin/ntop; then
			echo -e -n "\nntop is already running."
			rc_status -s
			exit
		fi
		## Start daemon with startproc(8). If this fails
		## the echo return value is set appropriate.
		if ! /usr/sbin/passcheck ; then
			echo -e -n "\nntop admin password is not yet set. " 
			echo -e -n "Run \n\t${warn}ntop -P /var/lib/ntop -A -u $NTOP_USER${rc_reset}\nmanually "
			rc_status -u
			exit
		else
			if [ -z $NTOP_OPTIONS ]; then
				setup_options
			fi
			startproc -q $PROGRAM $NTOP_OPTIONS
		fi
		rc_status -v
	;;
    stop)
		echo -n "Shutting down service ntop "
		## Stop daemon with killproc(8) and if this fails
		## set echo the echo return value.
		killproc -TERM $PROGRAM
		rc_status -v
	;;
    try-restart)
		$0 status
		if test $? = 0; then
			$0 restart
		else
			rc_reset
		fi
		rc_status
	;;
    restart)
		$0 stop
		$0 start
		rc_status
	;;
    reload|force-reload)
		echo -n "Reload service ntop "
		killproc -HUP $PROGRAM
		rc_status -v
	;;
    status)
		echo -n "Checking for service ntop: "
		## Check status with checkproc(8), if process is running
		## checkproc will return with exit status 0.
		checkproc $PROGRAM
		rc_status -v
	;;
	probe)
		test "$CONFFILE" -nt /var/run/ntop.pid && echo reload
	;;
    *)
		echo "Usage: $0 {start|stop|restart|reload|force-reload|status|try-restart|probe}"
		exit 1
	;;
esac
rc_exit