#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          zarafa-spooler
# Required-Start:    $syslog $network $remote_fs
# Required-Stop:     $syslog $network $remote_fs
# Should-Start:      zarafa-server
# Should-Stop:       zarafa-server
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# X-UnitedLinux-Default-Enabled:   yes
# Short-Description: Zarafa Collaboration Server's Spooler Daemon
# Description:       The Zarafa Spooler is responsible for converting
#                    MAPI messages to the internet format and sending
#                    using your MTA as configured.
### END INIT INFO

. /etc/rc.status
rc_reset

SPOOLERCONFIG=/etc/zarafa/spooler.cfg
SPOOLERPROGRAM=/usr/sbin/zarafa-spooler

# Sanity checks.
#[ -f $SPOOLERCONFIG ] || exit 0
[ -x $SPOOLERPROGRAM ] || exit 0

SPOOLERCONFIG_OPT=""
[ ! -z $SPOOLERCONFIG -a -f $SPOOLERCONFIG ] && SPOOLERCONFIG_OPT="-c $SPOOLERCONFIG"

[ -f /etc/sysconfig/zarafa ] && . /etc/sysconfig/zarafa
if [ -z "$ZARAFA_LOCALE" ]; then
	ZARAFA_LOCALE="C"
fi

spooler=`basename $SPOOLERPROGRAM`

case "$1" in
    start)
		echo -n "Starting Zarafa spooler "
		install -dm0775 -o zarafa -g zarafa /var/run/zarafad
		export LC_ALL=$ZARAFA_LOCALE
		export LANG=$ZARAFA_LOCALE
		$SPOOLERPROGRAM $SPOOLERCONFIG_OPT
		rc_status -v
		unset LC_ALL LANG
		;;

    stop)
		echo -n "Stopping Zarafa spooler "
		killproc $spooler
		rc_status -v
		;;

    restart)
		$0 stop
		$0 start
		;;

	reload)
		echo -n "Restarting Zarafa spooler: "
		killproc $spooler -SIGHUP
		rc_status -v
		;;

    status)
		echo -n "Checking for Zarafa spooler "
		checkproc $spooler
		rc_status -v
		;;

    *)
		;;
esac

rc_exit
