spamd - daemonized version of spamassassin

The goal is improving throughput performance for automated mail checking.

This is intended to be used alongside "spamc", a fast, low-overhead C client program.

See the README file in the "spamd" directory of the SpamAssassin distribution for more details.

"spamd" will check per-user config files for every message, changes to the system wide config files require either restarting spamd or forcing it to reload itself via SIGHUP for the changes to take effect.

When "spamd" receives a SIGHUP, it internally reloads itself, which means that it will change its pid and might not restart if its environment changed (ie. if it can't change back into its own directory). start "spamd" with -r to know its current pid. (not when I tried it!, ed)

boolean options (like --user-config) can be negated by adding no (--nouser-config).

Help display

-l,
--allow-tell
Allow learning/reporting
-c,
--create-prefs
Create user preferences files
-C path,
--configpath=path
Path for default config files
--siteconfigpath=path Path for site configs
--cf='config line' Additional line of configuration
-d,
--daemonize
Daemonize
-h,
--help
Print usage message
-i [ipaddr],
--listen-ip=ipaddr
Listen on the IP ipaddr
--ipv4only,
--ipv4-only,
--ipv4
Disable attempted use of ipv6 for DNS
-p port,
--port=port
Listen on specified port
-m num,
--max-children=num
Allow maximum num children
--min-children=num Allow minimum num children
--min-spare=num Lower limit for number of spare children
--max-spare=num Upper limit for number of spare children
--max-conn-per-child=num Maximum connections accepted by child before it is respawned
--round-robin Use traditional prefork algorithm
--timeout-tcp=secs Connection timeout for client headers
--timeout-child=secs Connection timeout for message checks
-q,
--sql-config
Enable SQL config (needs -x)
-Q,
--setuid-with-sql
Enable SQL config (needs -x, enables use of -H)
--ldap-config Enable LDAP config (needs -x)
--setuid-with-ldap Enable LDAP config (needs -x, enables use of -H)
--virtual-config-dir=dir Enable pattern based Virtual configs (needs -x)
-r pidfile,
--pidfile
Write the process id to pidfile
-s facility,
--syslog=facility
syslog facility
--syslog-socket=type How to connect to syslogd
-u username,
--username=username
Run as username
-g groupname,
--groupname=groupname
Run as groupname
-v,
--vpopmail
Enable vpopmail config
-x,
--nouser-config
Disable user config files
--auth-ident Use ident to authenticate spamc user
--ident-timeout=timeout Timeout for ident connections
-A host,...,
--allowed-ips=..,..
Limit ip addresses which can connect
-D,
--debug[=areas]
Print debugging messages (for areas)
-L,
--local
Use local tests only (no DNS)
-P,
--paranoid
Die upon user errors
-H [dir],
--helper-home-dir[=dir]
Specify a different HOME directory
--ssl Run an SSL server
--ssl-port port Listen on port for SSL connections
--ssl-version sslversion Specify SSL protocol version to use
--server-key keyfile Specify an SSL keyfile
--server-cert certfile Specify an SSL certificate
--socketpath=path Listen on given UNIX domain socket
--socketowner=name Set UNIX domain socket file's owner
--socketgroup=name Set UNIX domain socket file's group
--socketmode=mode Set UNIX domain socket file's mode
-V,
--version
Print version and exit

Detail explanation of options

-l,
--allow-tell
Allow learning and forgetting (to a local Bayes database), reporting and revoking (to a remote database) . The client issues a TELL command to tell what type of message is being processed and whether local (learn/forget) or remote (report/revoke) databases should be updated. the username passed is trusted (unless --auth-ident is used) so clients could maliciously learn messages for other users.
This is not a concern with an SQL Bayes store as users will typically have read-write access directly to the database, and can also use "sa-learn" with -u to achieve the same result.)
-c,
--create-prefs
Create user preferences (default: don't create).
-C path,
--configpath=path
default /usr/share/spamassassin
--siteconfigpath=path default /etc/mail/spamassassin
--cf=config line Add additional lines of configuration parsed after the configurtion files are read.
Multiple --cf arguments can be used, and each will be considered a separate line of configuration.
-d,
--daemonize
Detach from starting process and run in background
-h,
--help
 SpamAssassin Server version 3.2.4
running on Perl 5.8.8
with SSL support (IO::Socket::SSL 1.23)
with zlib support (Compress::Zlib 1.42)

warn: server socket setup failed, retry 1: spamd: could not create INET socket on 127.0.0.1:783: Permission denied
warn: server socket setup failed, retry 2: spamd: could not create INET socket on 127.0.0.1:783: Permission denied
error: spamd: could not create INET socket on 127.0.0.1:783: Permission denied
spamd: could not create INET socket on 127.0.0.1:783: Permission denied 
-V,
--version
Print version information, then exit without further action.
SpamAssassin Server version 3.3.1
  running on Perl 5.8.8
  with SSL support (IO::Socket::SSL 1.39)
  with zlib support (Compress::Zlib 2.033)
-i [IPaddr],
--listen-ip[=IPaddr],
--ip-address[=IPaddr]
Tells spamd to listen on the specified IP address (defaults to 127.0.0.1). If you specify no IP address after the switch, spamd will listen on all interfaces. (This is equal to the address 0.0.0.0). You can also use a valid hostname which will make spamd listen on the first address that name resolves to.
-p port,
--port=port
Optionally specifies the port number for the server to listen on (default: 783). If the --ssl switch is used, and --ssl-port is not supplied, then this port will be used to accept SSL connections instead of unencrypted connections. If the --ssl switch is used, and --ssl-port is set, then unencrypted connections will be accepted on the --port at the same time as encrypted connections are accepted at --ssl-port.
-q,
--sql-config
Turn on SQL lookups even when per-user config files have been disabled with -x. this is useful for spamd hosts which don't have user's home directories but do want to load user preferences from an SQL database. If your spamc client does not support sending the "User:" header, like "exiscan", then the SQL username used will always be nobody. This inhibits the setuid() behavior, so the "-u" option is required. If you want the setuid() behaviour, use "-Q" or "--setuid-with-sql" instead.
--ldap-config Turn on LDAP lookups. This is completely analog to "--sql-config", only it is using an LDAP server. Like "--sql-config", this disables the setuid behavior, and requires "-u". If you want it, use "--setuid-with-ldap" instead.
-Q,
--setuid-with-sql
Turn on SQL lookups even when per-user config files have been disabled with -x and also setuid to the user. This is useful for spamd hosts which want to load user preferences from an SQL database but also wish to support the use of -H (Helper home directories.)
--setuid-with-ldap Turn on LDAP lookups even when per-user config files have been disabled with -x and also setuid to the user. This is again completely analog to "--setuid-with-sql", only it is using an LDAP server.
--virtual-config-dir=pattern This option specifies where per-user preferences can be found for virtual users, for the -x switch. The pattern is used as a base pattern for the directory name. Any of the following escapes can be used:

%u -- replaced with the full name of the current user, as sent by spamc. %l -- replaced with the 'local part' of the current username. In other words, if the username is an email address, this is the part before the "@" sign. %d -- replaced with the 'domain' of the current username. In other words, if the username is an email address, this is the part after the "@" sign. %% -- replaced with a single percent sign (%).

So for example, if "/vhome/users/%u/spamassassin" is specified, and spamc sends a virtual username of "jm@example.com", the directory "/vhome/users/jm@example.com/spamassassin" will be used.

The set of characters allowed in the virtual username for this path are restricted to:

A-Z a-z 0-9 - + _ . , @ =

All others will be replaced by underscores ("_").

This path must be a writable directory. It will be created if it does not already exist. If a file called user_prefs exists in this directory (note: not in a ".spamassassin" subdirectory!), it will be loaded as the user's preferences. The Bayes databases for that user will be stored in this directory.

Note that this requires that -x is used, and cannot be combined with SQL- or LDAP-based configura- tion.

The pattern must expand to an absolute directory when spamd is running daemonized (-d).

Currently, use of this without -u is not supported. This inhibits setuid.

-r pidfile,
--pidfile=pidfile
Write the process ID of the spamd parent to the file specified by pidfile. The file will be unlinked when the parent exits. Note that when running with the -u option, the file must be writable by that user.
-v,
--vpopmail
Enable vpopmail config. If specified with with -u set to the vpopmail user, this allows spamd to lookup/create user_prefs in the vpopmail user's own maildir. This option is useful for vpopmail virtual users who do not have an entry in the system /etc/passwd file.

Currently, use of this without -u is not supported. This inhibits setuid.

-s facility,
--syslog=facility
mail default. With syslog it is essential to send a SIGHUP to the spamd daemon when restarting syslogd. Perl considers the disappearance of the connection to the syslogd a fatal error.

file output goes to spamd.log. not syslog.

facility is interpreted as a file name to log to if it contains any characters except a-z and 0-9.
Restart spamd with SIGHUP when the log file (independent of syslogd) is rotated. Logging to a file does not use locking, don't intermix logging from spamd and other processes into the same file. use mail

null disables logging

stderr output will be written to stderr not syslog. (useful when running "spamd" under the "daemontools" package.)

--syslog-socket=type How messages should send to syslogd: "unix", "inet" or "none".
Default unix falling back to inet if perl detects an error.

Some platforms, or versions of perl, are shipped with dysfunctional versions of the Sys::Syslog package which do not support some socket types, so you may need to set this.
If you get error messages regarding __PATH_LOG or similar from spamd, try changing this setting.

The socket type "file" is used internally and should not be specified. Use the "-s" switch instead.

-u username,
--username=username
Run as the named user. If this option is not set, the default behaviour is to setuid() to the user running "spamc", if "spamd" is running as root.

Note: "--username=root" is not a valid option. If specified, "spamd" will exit with a fatal error on startup.

-g groupname,
--groupname=groupname
Run as the named group if --username is being used. If this option is not set when --username is used then the primary group for the user given to --username is used.
-x,
--nouser-config,
--user-config
Turn off (on) reading of per-user configuration files (~/user_prefs). default --user-config

Does not influence the SQL, LDAP or Virtual Config Dir settings.

--auth-ident Verify the username provided by spamc using ident. only useful if connections are only allowed from trusted hosts (because an identd that lies is trivial to create) and if spamc REALLY SHOULD be running as the user it represents. Connections are terminated immediately if authentication fails. In this case, spamc will pass the mail through unchecked. Failure to connect to an ident server, and response timeouts are considered authentication failures. This requires that Net::Ident be installed.
--ident-timeout=seconds for a response to ident queries. If the timeout is exceeded mail will not be processed.
Setting this to 0 results in no timeout is STRONGLY discouraged. default 5 .
-A host,...,
--allowed-ips=host,...
a list of authorized hosts or networks which can connect to this spamd instance.
Accepts single IP addresses, ranges in address/masklength CIDR format, or ranges of IP addresses by listing 3 or less octets with a trailing dot.
Hostnames are not supported. Can be specified multiple times, or can take a list of addresses separated by commas. Examples:
-A 10.11.12.13 -- only allow connections from 10.11.12.13.
-A 10.11.12.13,10.11.12.14 -- only allow connections from 10.11.12.13 and 10.11.12.14.
-A 10.200.300.0/24 -- allow connections from any machine in the range "10.200.300.*".
-A 10. -- allow connections from any machine in the range "10.*.*.*".
Default: connections are only accepted from 127.0.0.1 (localhost ).
-D [area,...],
--debug [area,...]
Produce debugging output. If no areas are listed, all debugging information is printed. Diagnostic output can also be enabled for each area individually; area is the area of the code to instrument. For example, to produce diagnostic output on bayes, learn, and dns, use: spamassassin -D bayes,learn,dns Higher priority informational messages that are suitable for logging in normal circumstances are available with an area of "info".

See Wiki.Apache.org/spamAssassin/DebugChannels

--ipv4only,
--ipv4-only,
--ipv4
Do not use IPv6 for DNS tests.
-L,
--local
Perform only local tests (i.e. skip DNS and other network tests).
-P,
--paranoid
Die on user errors (for the user passed from spamc) instead of falling back to user nobody and using the default configuration.
performance related options
-m number,
--max-children=number
maximum of children to spawn. Spamd will spawn this many children, then sleep in the background until one exits, the spawns a new child if necessary.

Incoming connections can still occur if all of the children are busy. Those connections will be queued waiting for a free child. The minimum 1, default 5. There is a OS maximum connections that can be queued
Use perl -MSocket -e'print SOMAXCONN' to display it ( 128 on ed's system 3/24/11). If set too high for the available memory, performance will be degraded because of swapping

--min-children=number to be kept running. The minimum 1, default 1.
--min-spare=number The lower limit for the number of spare children allowed to run. A spare, or idle, child is one that is not handling a scan request. If there are too few spare children available, a new server will be started every second. The default 1.
--max-spare=number The upper limit for the number of spare children allowed to run. If there are too many spare children, one will be killed every second until the number of idle children is in the desired range. default 2.
--max-conn-per-child=number maximum number of connections each child should process before exiting and letting the master spamd process spawn a new child. The minimum 1, default 200.
--round-robin Disable "spamd" efforts to keep a small number of "hot" child processes as busy as possible, and keep any others as idle as possible, similar to the Apache httpd server scaling algorithm.
All processes receive an equal load and no scaling takes place.
--timeout-tcp=seconds to wait for headers from a client (spamc) before closing the connection. The minimum 1, default 30, and 0 will disable socket timeouts.
--timeout-child=seconds to wait for a spamd child to to process or check a message.
The minimum 1, default 300( 5 minutes !), and 0 disables timeouts.
Secure / Encrypted related options
--ssl Accept only SSL connections on the associated port.
The IO::Socket::SSL perl module must be installed.

Without --ssl-port, --port will be used to accept SSL connections instead of unencrypted connections.
With --ssl-port, unencrypted connections will be accepted on the --port, at the same time as encrypted connections are accepted at --ssl-port.

--ssl-port=port
--ssl-version=sslversion SSL protocol version to use, one of sslv2, sslv3, tlsv1, or sslv23.
Default: sslv23, is the most flexible, accepting a SSLv2 or higher hello handshake, then negotiating use of SSLv3 or TLSv1 protocol if the client can accept it.
Specifying --ssl-version implies --ssl.
--server-key keyfile
--server-cert certfile
Unix vs TCP socket related options
--socketpath pathname Listen on UNIX domain path pathname instead of a TCP socket. Warning: BSD bug for paths of over 100 bytes (SpamAssassin bug 4380).
Error : 'could not find newly-created UNIX socket' with the path truncated indicates this. Use a shorter path.
By default --socketpath inhibits SSL connections and unencrypted TCP connections.
To enable them, specify --port and/or --ssl-port explicitly.
--socketowner Uname Set UNIX domain socket to be owned by the Uname. Requires that spamd be started as "root", and if "-u" is used, that user needs write permissions to unlink the file.
--socketgroup Gname Set UNIX domain socket to be owned by the group named Gname.
--socketmode ugo Set UNIX domain socket to use the octal mode ugo. If "-u" is used, that user needs write permissions.
-H directory,
--helper-home-dir=directory
external programs such as Razor, DCC, and Pyzor should have a HOME environment variable set to a specific directory. The default is to use the HOME environment variable setting from the shell running spamd. By specifying no argument, spamd will use the spamc caller's home directory .
SEE ALSO spamc(1) spamassassin(1) Mail::SpamAssassin::Conf(3) Mail::SpamAssassin(3)