#!/bin/sh
#
# courier-authlib	courier-authlib
#
# chkconfig:	345 85 15
# description:	courier-authlib
#

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

# Get network config
. /etc/sysconfig/network

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

# 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 courier-authlib
		exit 1
	fi
else
	exit 0
fi

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/courier-authlib ]; then
		msg_already_running courier-authlib
		return
	fi

	msg_starting courier-authlib
	daemon /usr/sbin/authdaemond start
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/courier-authlib
}

stop() {
	# Stop daemons.
	if [ ! -f /var/lock/subsys/courier-authlib ]; then
		msg_not_running courier-authlib
		return
	fi

	msg_stopping courier-authlib
	daemon /usr/sbin/authdaemond stop
	rm -f /var/lock/subsys/courier-authlib >/dev/null 2>&1
}

reload() {
	if [ ! -f /var/lock/subsys/courier-authlib ]; then
		msg_not_running courier-authlib
		RETVAL=7
		return
	fi

	msg_reloading courier-authlib
	daemon /usr/sbin/authdaemond restart
	RETVAL=$?
}

condrestart() {
	if [ ! -f /var/lock/subsys/courier-authlib ]; then
		msg_not_running courier-authlib
		RETVAL=$1
		return
	fi

	stop
	start
}

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

exit $RETVAL
