#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

opts="${opts} reload"

depend() {
	need net
	before mta
	after clamav dspam spamd mysql postgresql
}

start() {
	ebegin "Starting sagator"
	if [ "${SAGATOR_CONFIGURED}" -ne "1" ]; then
		eerror "Sagator has not been configured yet!"
		eerror "Please consult Sagator's documentation"
		eerror "and edit /etc/mail/sagator/sagator.conf appropriately!"
		eerror "Do not forget to set the SAGATOR_CONFIGURED variable in"
		eerror "/etc/conf.d/sagator to 1 (one), otherwise Sagator"
		eerror "will refuse to start!"
				
		eend 1 "Failed to start stagator"
	else
		if [ "${SAGATOR_OPTS}" != "" ]; then
			start-stop-daemon --start --quiet --pidfile "${SAGATOR_PID}" \
				--exec /usr/sbin/sagator -- "${SAGATOR_OPTS}"
		else
			start-stop-daemon --start --quiet --pidfile "${SAGATOR_PID}" \
				--exec /usr/sbin/sagator
		fi
		eend $? "Failed to start sagator"
	fi
}

stop() {
	ebegin "Stopping sagator"
	start-stop-daemon --stop --quiet --pidfile "${SAGATOR_PID}"
	/usr/sbin/sagator --wait
	eend $? "Failed to stop sagator"
	rm -f "${SAGATOR_PID}"
}

reload() {
	ebegin "Reloading sagator"
	start-stop-daemon --stop --quiet --signal HUP --pidfile "${SAGATOR_PID}"
	eend $? "Failed to reload sagator"
}
