#!/bin/sh
#
#  Copyright (c) 2000-2002 QoSient, LLC
#  All rights reserved.
# 
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
# 
#
# argus      This shell script takes care of starting and stopping
#            argus.
#
# chkconfig: 2345 55 45
# description: argus-2.0 generates network transaction audit records.
# processname: argus
# config: /etc/argus.conf

#
# The assumption here is that /etc/argus.conf specifies ARGUS_DAEMON=yes.
# If not the system will hang running argus.  If this is not set, change
# "daemon argus" below to "daemon argus -d"
#

# Source function library.
if [ -f /etc/init.d/functions ]; then 
. /etc/init.d/functions
else
if [ -f /etc/rc.d/init.d/functions ]; then 
. /etc/init.d/functions
fi
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1


# Set argus path by defining $ARGUSHOME for this script.
# If argus was installed in another way, modify PATH to
# include the directory where the argus binary was installed.

ARGUSDIR=/usr/local/sbin
ARGUSHOME=$ARGUSDIR
export PATH=$ARGUSHOME:$PATH

[ -f $ARGUSHOME/argus ] || exit 1

RETVAL=0

start() {
	# Start daemons.

	echo -n "Starting argus: "
        if [ ! -e /etc/argus.conf ]
        then
                if [ ! -d /var/log/argus ]
                then
                        mkdir /var/log/argus
                fi
                argus -de `hostname` -w /var/log/argus/argus.out \
                        > /dev/null 2>&1
                RETVAL=$?
        else
		argus -d > /dev/null 2>&1 && success || failure
		RETVAL=$?
	fi
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/argus
	echo
}

stop() {
	# Stop daemons.
	echo -n "Shutting down argus: "
	killproc argus
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/argus
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  condrestart)
	if [ -f /var/lock/subsys/argus ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
  status)
	status argus
	RETVAL=$?
	;;
  *)
	echo "Usage: argus {start|stop|restart|condrestart|status}"
	exit 1
	;;
esac
exit 0
