#!/bin/sh
#
#  Argus-5.0 Software.  Argus Startup Script
#  Copyright (c) 2000-2024 QoSient, LLC
#  All rights reserved.
# 
# This program is free software, released under the GNU General
# Public License; 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 3, or any later version.
#
# Other licenses are available through QoSient, LLC.
# Inquire at info@qosient.com.
#
# This program is distributed 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.
# 
#  Written by Carter Bullard
#  QoSient, LLC
# 
#
# argus -    This shell script takes care of starting and stopping
#            argus, on RH Linux.  Should be useful for other versions.
#
# chkconfig: 2345 55 45
# description: argus-3.0 generates network transaction audit records.
# processname: argus
# config: /etc/argus.conf

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

# 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 $RETVAL
