Attached is what I use, found it on a webpage about installing SA when I
was going through it. Customized slightly for my local usernames and ways
of doing things.
When spamd dies, all mail continues to come through, it just doesn't get
analyzed by SA until spamd gets restarted.
Here's my config bits:
Postfix:
master.cf:
smtp inet n - n - - smtpd
-o content_filter=spamchk:dummy
spamchk unix - n n - 20 pipe
flags=Rq user=spamfilter argv=/usr/local/bin/spamchk -f ${sender}
-- ${recipient}
attached files:
spamchk - the filter script that gets called, pushes messages over to
spamc... note I commented out the bottom half of the script snice I don't
use that functionality currently, but may on other boxes in the future so
I left it there for reference.
spamdcheck.sh - wrote this scruipt to run every 5 minutes to check to see
if spamd is running. I've had instances where spamd just dies in the
middle of the night, but leaves the pidfile there, so I wrote this to
check and restart... might be crude, if anyone has suggestions on
bettering it, please do (also it monitors the number of spamd children to
tell me if I need to adjust child parameters if I'm running too many
processes).
Any questions, let me know.
-Gary
On Fri, 7 Apr 2006, James Keating wrote:
Michael Monnerie wrote:
On Freitag, 7. April 2006 14:09 James Keating wrote:
Any other thoughts?
I just found this:
http://wiki.apache.org/spamassassin/IntegratePosfixViaSpampd
mfg zmi
I have already tried this script and it was very close to what I was wanting,
but it does not connect to spamd in any manner. It actually uses the perl
libraries to interact with spamassassin in it's own manner, plus it is not
designed to use per user preferences/bayes/awl.
Thanks anyway Michael.
- James
#!/bin/sh
#########################################################################################
# SpamAssassin Spamd checking script
#
#
#
# Original script written by Gary Margiotta ([EMAIL PROTECTED]) 3/2006
#
#
#
# Run the check to see if spamd is running by running a ps and checking the
number of #
# lines returned. If the test returns with less then 3 process lines, assume
that #
# spamd is not running, since there should be no less than 6 processes active
at #
# any given time. In that case, check for a stale pidfile, remove it and then
restart #
# spamd with the usual startup parameters, and mail the output to the admin to
let them #
# know the process died and was restarted automatically.
#
#
#
#########################################################################################
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin;
export PATH;
DATE=`date "+%Y%m%d%H%M"`
SPAMDHOME="/data/home/spamd"
LOGFILE="/tmp/spamdrestart-${DATE}.txt"
PIDFILE="spamd.pid"
PSCHECK=`ps -ax | grep spamd | wc -l`
PSLOG="/tmp/pschecksa.log"
# Running the check and outputting to logfile for testing purposes
if [ -f ${PSLOG} ];
then
rm -f ${PSLOG}
fi
echo ${PSCHECK} > ${PSLOG}
#
# As an aside, check to see whether we need to adjust the number of child
# processes running.
#
if [ "${PSCHECK}" -gt "16" ];
then
echo " ${DATE} " >>
${LOGFILE}
echo "" >> ${LOGFILE}
echo "spamd children exceeded 15, consider bumping max" >> ${LOGFILE}
echo "" >> ${LOGFILE}
cat ${LOGFILE} | mail [EMAIL PROTECTED]
exit 0
fi
# Here's the meat of it
if [ "${PSCHECK}" -le "5" ];
then
echo " ${DATE} " >>
${LOGFILE}
echo "###########################################################" >>
${LOGFILE}
echo "# #" >>
${LOGFILE}
echo "# spamd doesn't appear to be running, attemping restart #" >>
${LOGFILE}
echo "# #" >>
${LOGFILE}
echo "###########################################################" >>
${LOGFILE}
#
# Checking for an existing pidfile
#
if [ -f "${SPAMDHOME}/${PIDFILE}" ];
then
echo "" >> ${LOGFILE}
echo "Old pidfile found, removing..." >> ${LOGFILE}
rm -f ${SPAMDHOME}/${PIDFILE}
echo "${SPAMDHOME}/${PIDFILE} removed." >> ${LOGFILE}
echo "" >> ${LOGFILE}
fi
echo "" >> ${LOGFILE}
echo "Restarting spamd..." >> ${LOGFILE}
spamd --daemonize --username spamd --max-children=20 --min-spare=5
--pidfile ${SPAMDHOME}/${PIDFILE} -s local5
echo "Done." >> ${LOGFILE}
echo "" >> ${LOGFILE}
echo "" >> ${LOGFILE}
sleep 10
if [ -f "${SPAMDHOME}/${PIDFILE}" ];
then
echo " ${DATE}
" >> ${LOGFILE}
echo
"###########################################################" >> ${LOGFILE}
echo "# #" >>
${LOGFILE}
echo "# auto-restart successful
#" >> ${LOGFILE}
echo "# #" >>
${LOGFILE}
echo
"###########################################################" >> ${LOGFILE}
echo "" >> ${LOGFILE}
cat ${LOGFILE} | mail [EMAIL PROTECTED]
exit 0
else
echo " ${DATE}
" >> ${LOGFILE}
echo
"###########################################################" >> ${LOGFILE}
echo "# #" >>
${LOGFILE}
echo "# auto-restart unsuccessful, please manually restart
#" >> ${LOGFILE}
echo "# #" >>
${LOGFILE}
echo
"###########################################################" >> ${LOGFILE}
echo "" >> ${LOGFILE}
cat ${LOGFILE} | mail [EMAIL PROTECTED]
cat ${LOGFILE} | mail [EMAIL PROTECTED]
exit 0
fi
fi
#!/bin/sh
# -----------------------------------------------------------------
# File: spamchk
#
# Purpose: SPAMASSASIN shell-based filter
#
# Location: /usr/local/bin
#
# Usage: Call this script from master.cf (Postfix)
#
# Certified: GENTOO Linux, Spamassassin 3.0, Postfix
# -----------------------------------------------------------------
# Variables
SENDMAIL="/usr/sbin/sendmail -i"
EGREP=/usr/bin/egrep
# Exit codes from <sysexits.h>
EX_UNAVAILABLE=69
# Number of *'s in X-Spam-level header needed to sideline message:
# (Eg. Score of 5.5 = "*****" )
SPAMLIMIT=8
# Clean up when done or when aborting.
trap "rm -f /var/tmp/out.$$" 0 1 2 3 15
# Pipe message to spamc
cat | /usr/local/bin/spamc -u spamfilter > /var/tmp/out.$$
# Are there more than $SPAMLIMIT stars in X-Spam-Level header? :
#if $EGREP -q "^X-Spam-Level: \*{$SPAMLIMIT,}" < /var/tmp/out.$$
#then
# Option 1: Move high scoring messages to sideline dir so
# a human can look at them later:
# mv out.$$ $SIDELINE_DIR/`date +%Y-%m-%d_%R`-$$
# Option 2: Divert to an alternate e-mail address:
# $SENDMAIL [EMAIL PROTECTED] < /var/tmp/out.$$
# Option 3: Delete the message
# rm -f /var/tempfs/out.$$
#else
$SENDMAIL "$@" < /var/tmp/out.$$
#fi
# Postfix returns the exit status of the Postfix sendmail command.
exit $?