#!/bin/sh
#
# Startup script for the DNS caching server
#
# chkconfig:	2345 81 45
# description:	Anubis is an outgoing mail processor, and the SMTP tunnel.
# processname:	anubis
# config:	/etc/anubisrc

# Set some frequently user variables
SERVICE=anubis
LOCKFILE=/var/lock/subsys/$SERVICE
MSG=$SERVICE
PROG=$SERVICE

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

# Get network config
. /etc/sysconfig/network

# 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 $MSG
		exit 1
	fi
else
	exit 0
fi

# Get service config
[ -f "/etc/sysconfig/$SERVICE" ] && . "/etc/sysconfig/$SERVICE"

start() {
  	if [ ! -f "$LOCKFILE" ]; then
		msg_starting "$MSG"
		daemon $PROG
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch $LOCKFILE
	else
		msg_already_running $MSG
	fi
}

stop() {
  	if [ -f "$LOCKFILE" ]; then
		msg_stopping "$MSG"
		killproc $PROG
		rm -f $LOCKFILE  >/dev/null 2>&1
	else
		msg_not_running "$MSG"
	fi
}

condrestart() {
	if [ -f "$LOCKFILE" ]; then
		stop
		start
	else
		msg_not_running "$MSG"
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status $PROG
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
