#! /bin/sh

# Init file for qico mailer.
#
# chkconfig: 2345 86 14
# description: qico mailer
#
# processname: qico
# config: /etc/ftn/qico.conf

WITHOUT_RC_COMPAT=1

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

LOCKFILE=/var/lock/subsys/qico
RETVAL=0

do_nodelist()
{
	action $"Compiling nodelists:" qico -n || exit
}

do_config_sanity_check()
{
	action $"Checking qico configuration:" qico -t || exit
}

start()
{
	# Compile nodelists
	do_nodelist

	start_daemon --lockfile "$LOCKFILE" --user ftn -- qico -d
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --lockfile "$LOCKFILE" --expect-user ftn qico
	RETVAL=$?
	return $RETVAL
}

restart()
{
	do_config_sanity_check
	stop
	start
}

reload()
{
	do_config_sanity_check
	msg_reloading qico
	stop_daemon --expect-user ftn -HUP qico
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	check)
		do_config_sanity_check
		;;
	status)
		status --expect-user ftn qico
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|check|status}"
		RETVAL=1
esac

exit $RETVAL
