#!/bin/sh
#
# tac_plus	This shell script takes care of starting and stopping
#		tac_plus (TACACS+ daemon).
#
# chkconfig:	235 80 20
# description:	tac_plus is TACACS+ daemon.
# processname:	tac_plus
# config:	/etc/tacacs/tac_plus.cfg
# pidfile:	/var/run/tac_plus.pid

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

# Source networking config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/tac_plus ] && . /etc/sysconfig/tac_plus

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down tac_plus
		exit 1
	fi
else
	exit 0
fi

tacacs_config="/etc/tacacs/tac_plus.cfg"

[ -f $tacacs_config ] || exit 0

if [ -z $TACACS_PORT ]; then
    TACACS_PORT=49
fi

if [ -z $TACACS_DEBUG_LEVEL ]; then
    TACACS_DEBUG_LEVEL=0
fi

# See how we were called.
case "$1" in
  start)
	if [ ! -f /var/lock/subsys/tac_plus ]; then
		msg_starting TACACS+
		daemon tac_plus -C $tacacs_config  -d $TACACS_DEBUG_LEVEL -p $TACACS_PORT
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/tac_plus
	else
		msg_already_running TACACS+
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/tac_plus ]; then
		msg_stopping TACACS+
		killproc tac_plus
		rm -f /var/lock/subsys/tac_plus
	else
		msg_not_running TACACS+
	fi
	;;
  status)
	status tac_plus
	exit $?
	;;
  restart)
	$0 stop
	$0 start
	;;

  reload)
	if [ -f /var/lock/subsys/tac_plus ]; then
		msg_reloading TACACS+
		killproc --pidfile /var/run/tac_plus.pid -SIGUSR1 tac_plus
	else
		msg_not_running TACACS+
	fi
	exit $?
	;;
  test)
	echo "TACACS+ config being testing"
	/usr/sbin/tac_plus -P -C $tacacs_config -p $TACACS_PORT
	;;
  *)
	echo "Usage: %s {start|stop|status|restart|reload|test}"
	exit 1
esac

exit 0
