Sophie

Sophie

distrib > Fedora > 13 > x86_64 > media > updates > by-pkgid > 479fd06d7603638e209416a0ed68bcec > files > 64

psad-2.1.7-1.fc13.x86_64.rpm

#!/bin/bash
#
#   /etc/rc.d/init.d/psad
#
# Starts the psad daemon
#
# chkconfig: - 95 5
# description: The Port Scan Attack Detector (psad)
# processname: psad
#
# Return values according to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#

PATH=/sbin:/bin:/usr/bin:/usr/sbin
prog="psad"

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

# Allow anyone to run status
if [ "$1" = "status" ] ; then
	if [ -f /var/run/psad/kmsgsd.pid ]; then
	 	status /usr/sbin/kmsgsd
	fi
 	status /usr/sbin/psadwatchd
 	status /usr/sbin/psad
	RETVAL=$?
	exit $RETVAL
fi

# Check that we are root ... so non-root users stop here
test $EUID = 0  ||  exit 4

RETVAL=0

#
#   See how we were called.
#


start() {
	echo -n $"Starting $prog: "
	test -x /usr/sbin/psad || exit 5
	test -f /etc/psad/psad.conf  || exit 6

	# Check if psad is already running
	if [ ! -f /var/lock/subsys/psad ]; then
	    # Create empty fwdata file if it doesn't exist
	    /bin/touch /var/log/psad/fwdata
	    chown root.root /var/log/psad/fwdata
	    chmod 0600 /var/log/psad/fwdata
	    # Create fifo if it doesn't exist
	    if [ ! -p /var/lib/psad/psadfifo ]; then
		[ -e /var/lib/psad/psadfifo ] && \
		    /bin/rm -f /var/lib/psad/psadfifo
	        /bin/mknod -m 600 /var/lib/psad/psadfifo p
	    fi
	    chown root.root /var/lib/psad/psadfifo
	    chmod 0600 /var/lib/psad/psadfifo

	    unset HOME MAIL USER USERNAME
	    daemon /usr/sbin/psad
	    RETVAL=$?
	    echo
	    if test $RETVAL = 0 ; then
		touch /var/lock/subsys/psad
	    fi
	fi
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc /usr/sbin/psadwatchd
	if [ -f /var/run/psad/kmsgsd.pid ]; then
		killproc /usr/sbin/kmsgsd
	fi
	killproc /usr/sbin/psad
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/psad
	echo
        return $RETVAL
}


restart() {
	stop
	start
}	

reload() {
	test -f /etc/psad/psad.conf  || exit 6
	restart
}	

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

exit $RETVAL