#!/bin/sh
#
# portsentry    Start the portsentry Port Scan Detector
#
# author:	Aleksandr Blokhin 'Sass' <sass@altlinux.ru>
#
# chkconfig: - 98 02
# description: PortSentry Port Scan Detector is part of the Abacus Project 
#              suite of tools. The Abacus Project is an initiative to release 
#              low-maintenance, generic, and reliable host based intrusion 
#              detection software to the Internet community.
# processname: portsentry
# config /etc/portsentry/portsentry.conf

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" != "no" ] || exit

LOCKFILE=/var/lock/subsys/portsentry
RETVAL=0
MODES="atcp audp"

start()
{
	if [ -a $LOCKFILE ] ; then
	echo "Service portsentry is already running."
	else
	for i in $MODES ; do
	action $"Starting port scan detector: " /usr/sbin/portsentry -$i
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	echo
	done
	fi
}
stop()
{
	if [ -a $LOCKFILE ] ; then
	stop_daemon --lockfile "$LOCKFILE" --expect-user root portsentry
	RETVAL=$?
	return $RETVAL
	fi
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root portsentry
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
