#!/sbin/runscript # Tis init script takes care of starting the MTA processes for use # with MailScanner. opts="${opts} status reload startin startout stopin stopout restartin restartout" checkmta() { ebegin "checking MTA availability for MailScanner" if [ ${MTA} = 'sendmail' ]; then if [ -f ${SENDMAIL} ]; then eend 0 return else echo "Cannot find sendmail, check /etc/conf.d/mailscanner-mta" eend 1 exit fi elif [ ${MTA} = "postfix" ]; then if test -x ${POSTFIX} -a -f ${POSTFIXINCF}/main.cf \ -a -f ${POSTFIXOUTCF}/main.cf ; then eend 0 return else echo "Cannot find postfix and/or postfix configuration files," echo "Check /etc/conf.d/mailscanner-mta" eend 1 exit fi elif [ ${MTA} = "exim" ]; then if test -x ${EXIM} -a -f ${EXIMINCF} -a -f ${EXIMSENDCF}; then eend 0 return else echo "Cannot find exim and/or exim configuration files," echo "Check /etc/conf.d/mailscanner-mta" eend 1 exit fi else echo "Invalid MTA in /etc/conf.d/mailscanner-mta" eend 1 exit fi } aliasesetc() { /usr/bin/newaliases > /dev/null 2>&1 retval=$? if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then make -C /etc/mail -s let retval+=$? else for i in virtusertable access domaintable mailertable ; do if [ -f /etc/mail/$i ] ; then makemap hash /etc/mail/$i < /etc/mail/$i let retval+=$? fi done fi return ${retval} } startinreal () { if [ ${MTA} = "sendmail" ]; then ( cd /var/spool/mqueue.in; rm -f xf*) aliasesetc ${SENDMAIL} -bd -OPrivacyOptions=noetrn \ -ODeliveryMode=queueonly \ -OQueueDirectory=${INQDIR} \ -OPidFile=${INPID} retval=$? touch ${SMPID} chown ${MSPUSER}:${MSPGROUP} ${SMPID} 2> /dev/null ${SENDMAIL} -L sm-msp-queue -Ac -q15m -OPidFile=${SMPID} 2> /dev/null let retval+=$? return ${retval} elif [ ${MTA} = "postfix" ]; then ${POSTFIX} -c ${POSTFIXINCF} start 2> /dev/null return $? elif [ ${MTA} = "exim" ]; then ${EXIM} -c ${EXIMINCF} start 2> /dev/null return $? fi } startoutreal() { if [ ${MTA} = "sendmail" ]; then ${SENDMAIL} $([ -n "${QUEUETIME}" ] && echo -q${QUEUETIME}) \ -OPidFile=${OUTPID} return $? elif [ ${MTA} = "postfix" ]; then ${POSTFIX} -c ${POSTFIXOUTCF} start 2> /dev/null return $? elif [ ${MTA} = "exim" ]; then ${EXIM} -c ${EXIMSENDCF} -q15m 2> /dev/null return $? fi } stopinreal() { if [ ${MTA} = "sendmail" ]; then kill ${KILL_OPTS} `head -1 ${INPID}` 2> /dev/null retval=$? kill ${KILL_OPTS} `head -1 ${SMPID}` 2> /dev/null let retval+=$? return ${retval} elif [ ${MTA} = "postfix" ]; then ${POSTFIX} -c ${POSTFIXINCF} stop 2> /dev/null return $? fi } stopoutreal() { if [ ${MTA} = "sendmail" ]; then kill ${KILL_OPTS} `head -1 ${OUTPID}` 2> /dev/null return $? elif [ ${MTA} = "postfix" ]; then ${POSTFIX} -c ${POSTFIXOUTCF} stop 2> /dev/null return $? fi } depend() { need net use logger dns provide mta } start() { checkmta ebegin "Starting incoming ${MTA}" startinreal retval=$? eend ${retval} if [ ${retval} -gt 0 ]; then exit fi ebegin "Starting outgoing ${MTA}" startoutreal retval=$? eend ${retval} if [ ${retval} -gt 0 ]; then echo "Will attempt to stop incoming ${MTA}" stopinreal fi } stop() { checkmta if [ ${MTA} = "exim" ]; then ebegin "Stopping exim" killall ${KILL_OPTS} exim eend $? else ebegin "Stopping incoming ${MTA}" stopinreal eend $? ebegin "Stopping outgoing ${MTA}" stopoutreal eend $? fi } startin() { checkmta ebegin "Starting incoming ${MTA}" startinreal eend $? } startout() { checkmta ebegin "Starting outgoing ${MTA}" startoutreal eend $? } stopin() { checkmta if [ ${MTA} = "exim" ]; then ebegin "Stopping incoming exim" echo "It is not possible to stop only the incoming exim."; echo "Please use the stop option, then use startin or startout to restart" echo "the incoming or outgoing process." eend 1 else ebegin "Stopping incoming ${MTA}" stopinreal eend $? fi } stopout() { checkmta if [ ${MTA} = "exim" ]; then ebegin "Stopping outgoing exim" echo "It is not possible to stop only the outgoing exim."; echo "Please use the stop option, then use startin or startout to restart" echo "the incoming or outgoing process." eend 1 else ebegin "Stopping outgoing ${MTA}" stopoutreal eend $? fi } restartin() { stopin startin } restartout() { stopout startout } status() { if [ ${MTA} = 'sendmail' ]; then ebegin "Incoming Sendmail status" pid=`head -1 ${INPID}` alive=`ps ax | awk '{ print $1 }' | grep '^'$pid'$'` if [ -z "${alive}" ]; then eend 1; else eend 0; fi ebegin "Client submission Sendmail status" pid=`head -1 ${SMPID}` alive=`ps ax | awk '{ print $1 }' | grep '^'$pid'$'` if [ -z "${alive}" ]; then eend 1; else eend 0; fi ebegin "Outgoing Sendmail status" pid=`head -1 ${OUTPID}` alive=`ps ax | awk '{ print $1 }' | grep '^'$pid'$'` if [ -z "${alive}" ]; then eend 1; else eend 0; fi elif [ ${MTA} = 'postfix' ]; then echo "Sorry: status is not supported for postfix" elif [ ${MTA} = 'exim' ]; then echo "Sorry: status is not supported for exim" else echo "Invalid MTA in /etc/conf.d/mailscanner-mta" exit fi } reload() { if [ ${MTA} = 'sendmail' ]; then ebegin "Reloading Sendmail configuration" aliasesetc eend $? elif [ ${MTA} = 'postfix' ]; then ebegin "Reloading Incoming Postfix" ${POSTFIX} -c ${POSTFIXINCF} reload > /dev/null eend $? ebegin "Reloading Outgoing Postfix" ${POSTFIX} -c ${POSTFIXOUTCF} reload > /dev/null eend $? elif [ ${MTA} = 'exim' ]; then echo "Sorry: reload is not supported for exim" else echo "Invalid MTA in /etc/conf.d/mailscanner-mta" exit fi }