#!/sbin/svc

# The Postoffice MTA

MYLISTING="The Postoffice Mail Transfer Agent (SMTP MTA)"
CONTROL_GROUP="netconf"

# We use requires rather than depends_on cron here as whilst the MTA needs
# calls from cron to periodically run queues it is capable of performing
# most operations independently so it make little sense to stop it if cron
# should glitch for some reason.
depend() {
	depends_on net_base
        requires cron
}

start() {
	if [ -r $CONFDIR/mta ]
	then
	    source $CONFDIR/mta
	    if is_false $ENABLE
	    then
		if [ "X$scriptmode" = "Xrcscript" ]
		then
		    # Don't start from RC startup if explicitly disabled.
		    exit 0
		else
		    echo "Starting despite not being enabled in $CONFDIR/mta"
		fi
	    fi
	fi

	if [ /etc/mail/aliases -nt /etc/mail/aliases.db ]
	then
	    echo "updating mail aliases"
	    newaliases
	fi

	daemonize_orig /usr/lib/postoffice -bd -d -q47m
}

stop() {
	killall -q postoffice
}
