#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          zarafa-monitor
# 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 Platform's Quota Monitor
# Description:       The Zarafa Quota Monitor watches the store sizes
#                    of users, and sends warning emails when limits are exceeded.
### END INIT INFO

. /etc/rc.status
rc_reset

MONITORCONFIG=/etc/zarafa/monitor.cfg
MONITORPROGRAM=/usr/sbin/zarafa-monitor

# Sanity checks.
#[ -f $MONITORCONFIG ] || exit 0
[ -x $MONITORPROGRAM ] || exit 0

MONITORCONFIG_OPT=""
[ ! -z $MONITORCONFIG -a -f $MONITORCONFIG ] && MONITORCONFIG_OPT="-c $MONITORCONFIG"

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

monitor=`basename $MONITORPROGRAM`

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

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

    restart)
		$0 stop
		$0 start
		;;

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

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

    *)
		;;
esac

rc_exit
