#!/bin/sh
#
# Startup script for psad
#
# chkconfig: 345 99 05
# description: The Port Scan Attack Detector (psad)
# processname: psad
# pidfile: /var/run/psad.pid
# config: /etc/psad/psad.conf
#
# $Id: psad-init.redhat,v 1.2 2003/10/14 05:05:12 mbr Exp $

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

restart() {
    $0 stop
    $0 start
}

# See how we were called.
case "$1" in
start)
    if grep -q psadfifo /etc/syslog.conf; then
        gprintf "Starting the psad daemons: "
        ### psad enables signature matching and auto
        ### danger level assignment by default, so
        ### command line args are not necessary here.
        daemon /usr/sbin/psad
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ]; then
            touch /var/lock/subsys/psad
        fi
    else
        gprintf "Syslog has not been configured to send kern.info messages to\n"
        gprintf "/var/lib/psad/psadfifo.  Do you need to run the psad installer?\n"
    fi
    ;;
stop)
    gprintf "Shutting down the psad psadwatchd daemon: "
        killproc psadwatchd
        echo
        gprintf "Shutting down the psad daemon: "
        killproc psad
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/psad
    echo
    gprintf "Shutting down the psad kmsgsd daemon: "
    killproc kmsgsd
    echo
    ;;
status)
    status kmsgsd
    status psad
    status psadwatchd
    ;;
restart|reload)
    restart
    ;;
condrestart)
    [ -f /var/lock/subsys/psad ] && restart || :
    ;;
*)
    gprintf "Usage: psad {start|stop|status|restart|reload|condrestart}\n"
    exit 1
esac
