#!/bin/sh
#
# atsar		This shell script takes care of initializing
#		the atsar system activity report subsystem.
#
# chkconfig:	2345 85 15
# description:	Atsar is a system activity report logging system.
#

# Source function library.
if [ -f /etc/rc.d/init.d/functions ]
then
	. /etc/rc.d/init.d/functions
else
	alias daemon=nice
fi

# Check binaries and configuration files.
[ -f /usr/bin/atsadc ] || exit 0

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/atsar ]; then
		# Run atsadc.
		msg_starting atsar
		daemon /usr/bin/atsadc /var/log/atsar/atsa`date +%d`
		RETVAL=$?
		rm -f /var/log/atsar/ftpstat  2> /dev/null
		rm -f /var/log/atsar/httpstat 2> /dev/null

		if [ -f /etc/atsar.conf ]; then
			/usr/bin/atsaftp
			/usr/bin/atsahttp
		fi
		echo
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/atsar
	else
		msg_already_running atsar
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/atsar ]; then
		msg_stopping atsar
		daemon rm -f /var/lock/subsys/atsar
	else
		msg_not_running atsar
	fi
	;;
  status)
	;;
#  reload)
#	# to be fixed
#	$0 stop
#	$0 start
#	exit $?
#	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
