Starting DSPAM

We are going to use DSPAM in daemon mode using the following command:

sudo /usr/local/bin/dspam --daemon &

If that works we need to reload the postfix configuration to enable our new content filter. You can do that by issuing the following command:

sudo postfix reload

This is of course the manual method of starting DSpam, but you want to be sure it starts after the next scheduled reboot. Because by the time you do that you will have forgotten all about it.

First we need to create a shell script that will start and stop DSpam in daemon mode. I’ve created a script called dspam_startup in /usr/local/bin next to all the other DSpam commands. It looks like:

# dspam: Starts dspam in daemon mode
# with minimal resources.
# processname: dspam
# pidfile: /var/run/
# Source function library.

start() {
 echo -n $"Starting dspam: "
 dspam --daemon 2>/dev/null &

stop() {
 echo -n $"Stopping dspam: "
 kill $(sudo cat /var/run/

# See how we were called.
case "$1" in



  echo $"Usage: $0 {start|stop|restart}"


exit $RETVAL

Please don’t forget to set the execute bit on the script to be able to use it:

sudo chmod +x /usr/local/bin/dspam_startup

Next we need to create the StartupItem scripts that are called during boot and shutdown processes. To do this you need to download the Dspam-startup.tar archive and extract as root into ‘/Library/StartupItems’.

The DSpam startup item looks like:

# DSPAM spam filter
# Richard5
. /etc/rc.common
StartService ()
     if [ "${DSPAMDAEMON:=-NO-}" = "-YES-" ]; then
          echo "Starting DSpam daemon"
          /usr/local/bin/dspam_startup start

StopService ()
     echo "Stopping DSpam daemon"
     /usr/local/bin/dspam_startup stop

RestartService ()
     if [ "${DSPAMDAEMON:=-NO-}" = "-YES-" ]; then
          echo "Restarting DSpam daemon"
          /usr/local/bin/dspam_startup restart
RunService "$1"

The file StartupParameters.plist will help in setting the correct order for programs to start to fulfill any dependencies. DSpam requires MySQL to be running and this file will help to accomplish this, the content should look like:

   Description  = "DSpam mail spam filter";
   Provides      = ("Dspam");
   Uses           = ("MySQL");

The last thing to do is to add the following line to the /etc/hostconfig file:


This controls if you want DSpam to be started after a reboot.


Next, how to train DSPAM using scripts.

8 Responses to “Starting DSPAM”

  1. Mwonge Richard Says:

    good document pretty straight to understand

  2. Stephen Says:

    what about StartupParameters.plist?

  3. Richard5 Says:

    Just keep it the same as the one you copied.

  4. Dave Says:

    Hi Richard5,

    i’m getting postfix/pipe[27194]: fatal: pipe_command: execvp /usr/local/bin/dspam: Permission denied

    any hints? :-)



  5. Dave Says:

    i did an:
    chmod o+x /usr/local/bin/dspam

    and now it seems to work.

    b.t.w. in your current config the serial is just in the header.. not in the body.

  6. Richard5 Says:

    @Dave, I don’t need the serial in the message, it looks ugly and it stays in the message when replying. Do you need it for some other purpose ?

  7. Dave Says:

    No. i just wondered, because your description looked like it should appear in the body. on the first look i thought i did something wrong and dspam isn’t running. in the header is fine :-) otherwise it would be really annoying :-)

    b.t.w. i am seeing “dspam[490]: query error: VERBOSE DEBUG (INFO ONLY – NOT AN ERROR): see sql.errors for more details” in my logs. but i dont know where to look for the sql.errors logfile.

    seems to be something like this problem:

  8. Richard5 Says:

    I will change the documentation !

    The error is for infomational purposes only, it’s not an error. The logfiles are somewhere in /usr/local/var/dspam