#!/bin/sh
#
# saslauthd	SASL AUTH Daemon
#
# chkconfig:	2345 40 60
# description:	SASL AUTH Daemon
# processname:	saslauthd
# pidfile:	/var/lib/sasl2/saslauthd.pid

# $Id: saslauthd.init,v 1.11 2009/02/03 15:36:18 glen Exp $

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

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

if [ "$SASL_AUTHMECH" ]; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -a $SASL_AUTHMECH"
fi

if [ "$SASL_RIMAP_HOSTNAME" ]; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -O $SASL_RIMAP_HOSTNAME"
fi

if is_yes "$SASLAUTHD_CACHE"; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -c"
fi

if [ "$SASLAUTHD_THREADS" ]; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -n $SASLAUTHD_THREADS"
fi

start() {
	if [ ! -f /var/lock/subsys/saslauthd ]; then
		msg_starting saslauthd
		daemon /usr/sbin/saslauthd $SASLAUTHD_OPTS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/saslauthd
	else
		msg_already_running saslauthd
	fi
}

stop() {
	if [ -f /var/lock/subsys/saslauthd ]; then
		msg_stopping saslauthd
		killproc saslauthd
		rm -f /var/lock/subsys/saslauthd /var/lib/sasl2/saslauthd.pid >/dev/null 2>&1
	else
		msg_not_running saslauthd
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/saslauthd ]; then
		stop
		start
	else
		msg_not_running saslauthd
		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 saslauthd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
