File spamass-milter.sysv of Package spamass-milter

#!/bin/bash
#
# Init file for SpamAssassin sendmail milter.
#
# chkconfig: - 79 21
# description: spamass-milter is a daemon that hooks into sendmail and \
#              routes email messages to spamassassin
#
# processname: spamass-milter
# config: %{_sysconfdir}/sysconfig/spamass-milter
# pidfile: %{_localstatedir}/run/spamass-milter.pid

### BEGIN INIT INFO
# Provides: spamass-milter
# Required-Start: $local_fs $network $syslog $named
# Required-Stop: $local_fs $network $syslog $named
# Default-Stop: 0 1 6
# Should-Start: spamd spamassassin
# Should-Stop: spamd spamassassin
# Short-Description: Start or stop SpamAssassin Milter
# Description: Spamass-milter is an add-on to sendmail that can route mail \
#       messages through SpamAssassin and mark or reject mail deemed \
#       to be spam
### END INIT INFO

# Default variables
PATH=/sbin:/bin:/usr/sbin:/usr/bin
RUN_AS_USER=sa-milt
SOCKET="%{_localstatedir}/run/spamass-milter/spamass-milter.sock"
SOCKET_OPTIONS=""
EXTRA_FLAGS=""
SYSCONFIG="%{_sysconfdir}/sysconfig/spamass-milter"

# If Postfix support package is installed, use a postfix-group-writable
# socket for communication with the MTA
if [ -d %{_localstatedir}/run/spamass-milter/postfix ]; then
	SOCKET="%{_localstatedir}/run/spamass-milter/postfix/sock"
	SOCKET_OPTIONS="-g postfix"
fi

# Read configuration
source %{_initrddir}/functions
for configfile in %{_sysconfdir}/sysconfig/network "${SYSCONFIG}"; do
	[ -r "${configfile}" ] && source "${configfile}"
done

[ -x %{_sbindir}/spamass-milter ] || exit 5

RETVAL=0
prog="spamass-milter"
desc="SpamAssassin milter"
pidfile=%{_localstatedir}/run/spamass-milter.pid

# Fix ownership of socket directory if necessary
chown ${RUN_AS_USER} %{_localstatedir}/run/spamass-milter

start() {
	echo -n $"Starting ${desc} (${prog}): "
	touch ${pidfile}
	chown ${RUN_AS_USER} ${pidfile}
	[ -x /sbin/restorecon ] && /sbin/restorecon ${pidfile}
	daemon --user ${RUN_AS_USER} %{_sbindir}/${prog} ${SOCKET_OPTIONS} -p ${SOCKET} -P ${pidfile} -f ${EXTRA_FLAGS}
	RETVAL=$?
	echo
	if [ ${RETVAL} -eq 0 ]; then
		touch %{_localstatedir}/lock/subsys/spamass-milter
		return 0
	else
		return 1
	fi
}

stop() {
	echo -n $"Shutting down ${desc} (${prog}): "
	rm -f %{_localstatedir}/lock/subsys/spamass-milter
	killproc ${prog}
	RETVAL=$?
	echo
	if [ ${RETVAL} -eq 0 ]; then
		rm -f ${pidfile}
		return 0
	else
		return 1
	fi
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|force-reload)
		if [ "x`pidof spamass-milter`" != x ]; then
			stop
			sleep 2
		fi
		start
		;;
	condrestart|try-restart)
		if [ -e %{_localstatedir}/lock/subsys/spamass-milter ]; then
			stop
			sleep 2
			start
		else
			exit 0
		fi
		;;
	status)
		status ${prog}
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
		exit 2
esac