Updating spamassassin rules using sa-update

Socrates

New member
Joined
Sep 22, 2008
Messages
4
Hi all,

The installation for spamassassin suggests to run sa-update from a cronjob regularly to update the spamd with new rules once in a while, however, the manual for sa-update says the following:

Note that "sa-update" will not restart "spamd" or otherwise cause a scanner to reload the now-updated ruleset automatically.

Instead, "sa-update" is typically used in something like the following manner:

sa-update && /etc/init.d/spamassassin reload

I've installed spamassassin version 3.3.1 using the spam.sh script as found in /usr/local/directadmin/scripts but this changes only /etc/init.d/exim startup script. I'm running debian 5.0.

As the exim reload command only reloads exim and not spamd this doesn't work either.

I think either the exim init script should be changed or a separate spamassassin script should be used which uses the --pidfile= option of spamd so we can do a kill -HUP to that pid on reload (spamd supports this).

What would be directadmin supported way of doing this?
 
I've decided to use the debian init scripts with some minor adjustments (since I'm using debian 5.0) to start/stop/reload the spamassassin. I've shamelessly ripped these out of the package spamassassin_3.2.5-2+lenny2_all.deb and thank the maintainer of the debian package for his work.

First I've installed the init script in /etc/init.d/spamassassin which is as follows
Code:
#! /bin/sh

### BEGIN INIT INFO
# Provides:       spamassassin
# Required-Start: $remote_fs
# Required-Stop:  $remote_fs
# Should-Start:   $network $syslog
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
### END INIT INFO

# Spamd init script
# June 2002
# Duncan Findlay

# Based on skeleton by Miquel van Smoorenburg and Ian Murdock

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/spamd
NAME=spamd
SNAME=spamassassin
DESC="SpamAssassin Mail Filter Daemon"
PIDFILE="/var/run/$NAME.pid"
XNAME=/usr/bin/perl

export TMPDIR=/tmp
# Apparently people have trouble if this isn't explicitly set...

# Defaults - don't touch, edit /etc/default/spamassassin
ENABLED=0
OPTIONS=""
NICE=

test -f /etc/default/spamassassin && . /etc/default/spamassassin

DOPTIONS="-d --pidfile=$PIDFILE"

if [ "$ENABLED" = "0" ]; then
    echo "$DESC: disabled, see /etc/default/spamassassin"
    exit 0
fi

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --pidfile $PIDFILE --exec $XNAME \
	    $NICE --oknodo --startas $DAEMON -- $OPTIONS $DOPTIONS
	echo "$NAME."
	;;

  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --pidfile $PIDFILE --exec $XNAME --oknodo
	echo "$NAME."
	;;

  reload|force-reload)
	echo -n "Reloading $DESC: "
	start-stop-daemon --stop --pidfile $PIDFILE --signal HUP --exec $XNAME
	echo "$NAME."
	;;

  restart)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --pidfile $PIDFILE --exec $XNAME \
	    --retry 5 --oknodo
	start-stop-daemon --start --pidfile $PIDFILE --exec $XNAME \
	    $NICE --oknodo --startas $DAEMON -- $OPTIONS $DOPTIONS

	echo "$NAME."
	;;

  *)
	N=/etc/init.d/$SNAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0

Make sure this file has the execute bit set (chmod +x /etc/init.d/spamassassin).

Next I've created the file /etc/default/spamassassin as follows:
Code:
# /etc/default/spamassassin
# Duncan Findlay

# WARNING: please read README.spamd before using.
# There may be security risks.

# Change to one to enable spamd
ENABLED=1

# Options
# See man spamd for possible options. The -d option is automatically added.

# SpamAssassin uses a preforking model, so be careful! You need to
# make sure --max-children is not set to anything higher than 5,
# unless you know what you're doing.

OPTIONS="--create-prefs --max-children 15"

# Pid file
# Where should spamd write its PID to file? If you use the -u or
# --username option above, this needs to be writable by that user.
# Otherwise, the init script will not be able to shut spamd down.
PIDFILE="/var/run/spamd.pid"

# Set nice level of spamd
#NICE="--nicelevel 15"

# Cronjob
# Set to anything but 0 to enable the cron job to automatically update
# spamassassin's rules on a nightly basis
CRON=1

The third file I edited was /etc/cron.daily/spamassassin which will run our rules update using sa-update daily, the file is as follows:
Code:
#!/bin/sh

# Duncan Findlay
# [email protected]

# Daily cronjob for SpamAssassin updates. This isn't pretty but it
# should do the job.

set -e

CRON=0

test -f /etc/default/spamassassin && . /etc/default/spamassassin

test -x /usr/bin/sa-update || exit 0
test -x /etc/init.d/spamassassin || exit 0

if [ "$CRON" = "0" ] ; then
    exit 0
fi

# Sleep for up to 3600 seconds
# Taken from apticron's cron.daily
RANGE=3600
number=`od -vAn -N2 -tu4 < /dev/urandom`
number=`expr $number "%" $RANGE`
sleep $number


# Update
umask 022
sa-update || exit 0

# Compile, if rules have previously been compiled, and it's possible
if [ -x /usr/bin/re2c -a -x /usr/bin/sa-compile -a -d /var/lib/spamassassin/compiled ]; then
    sa-compile > /dev/null 2>&1
fi

# Fixup perms -- group and other should be able to read and execute, 
# but never write.  Works around sa-compile's failure to obey umask.
if [ -d /var/lib/spamassassin ]; then
    chmod -R go-w,go+rX /var/lib/spamassassin/
fi

# Reload
if which invoke-rc.d >/dev/null 2>&1; then
    invoke-rc.d spamassassin reload > /dev/null 2>&1
else
    /etc/init.d/spamassassin reload > /dev/null 2>&1
fi

The cronjob file also needs to be executable, do chmod +x /etc/cron.daily/spamassassin

Next we need to remove starting of the spamd from the exim init script, the diff for /etc/init.d/exim is as follows:
Code:
--- exim.orig	2010-04-20 10:52:17.000000000 +0200
+++ exim	2010-04-20 10:52:40.000000000 +0200
@@ -35,3 +35,2 @@
         echo
-	if [ -e /usr/bin/spamd ]; then /usr/bin/spamd -d -c -m 15 1>/dev/null 2>/dev/null; fi
         ;;
@@ -42,5 +41,2 @@
         echo
-	
-	if [ -e /usr/bin/spamd ]; then $KILLALL -9 spamd; fi
-
         ;;

And finally we add the spamassassin to the boot startup scripts using
Code:
# update-rc.d spamassassin defaults
 
Back
Top