UNIX System Administration Handbook - Evi Nemeth [337]
Table 19.7 Prefixes for files in the mail queue
If subdirectories qf, df, or xf exist in a queue directory, then those pieces of the message are put in the proper subdirectory. The qf file contains not only the message header but also the envelope addresses, the date at which the message should be returned as undeliverable, the message’s priority in the queue, and the reason the message is in the queue. Each line begins with a single-letter code that identifies the rest of the line.
Each message that is queued must have a qf and df file. All the other prefixes are used by sendmail during attempted delivery. When a machine crashes and reboots, the startup sequence for sendmail should delete the tf, xf, and Tf files from each queue directory. The sysadmin responsible for mail should check occasionally for Qf files in case local configuration is causing the bounces.
The mail queue provides several opportunities for things to go wrong. For example, the filesystem can fill up (avoid putting /var/spool/mqueue and /var/spool/news on the same partition), the queue can become clogged, and orphaned mail messages can get stuck in the queue.
sendmail has a configuration option (confMIN_FREE_BLOCKS) to help manage disk space. When the filesystem that contains the mail queue gets too full, mail is rejected with a “try again later” error until more space has been made available. This option leaves a bit of slop space so mail starts being rejected before the filesystem is totally full and everything wedges.
If a major mail hub goes down, its MX backup sites can become overloaded with thousands of messages.18
sendmail can fork too many copies of itself and thrash a machine to death. To handle a temporarily clogged queue, you need to move the clog aside, continue processing new mail as usual, and run a separate copy of sendmail on the clogged queue after things quiet down.
See page 443 for more information about DNS MX records.
For example, with a single queue directory:
# kill 'head -1 sendmail.pid'
# mv mqueue cloggedqueue /* To another FS if necessary */
# mkdir mqueue /* Set owner/perms, too */
# chown root mqueue
# chmod 700 mqueue
# /usr/sbin/sendmail -bd -q1h &
When things settle down, run sendmail with the following flags:
# /usr/sbin/sendmail -oQ/var/spool/cloggedqueue -q
These flags point sendmail at the clogged queue directory and specify that sendmail should process it immediately. Repeat this command until the queue empties.
For giant clogs, consider sorting messages into different queues by the last digit of their message IDs, as shown in the following script:
#!/bin/csh -f
foreach suffix (0 1 2 3 4 5 6 7 8 9)
mkdir clog${suffix}
mv ?f*${suffix} clog${suffix}
sendmail -oQclog${suffix}
end
The point of separating messages into different queues is just to reduce the overhead of the linear directory search. Ten mini-queues will run faster than one big queue because sendmail is almost always I/O bound and not CPU bound.
The point at which the queue becomes clogged depends on the site and the hardware on which sendmail is running. Your system and the mail hub for aol.com, which processes millions of messages a day, will have different definitions of a clogged queue. See page 614 for information about measuring your traffic levels.
19.6 SENDMAIL CONFIGURATION
sendmail’s actions are controlled by a single configuration file, sendmail.cf, which is kept in /etc/mail (it was formerly found in /etc or /usr/lib). We call it the config file for short. It determines sendmail’s
• Choice of delivery agents
• Address rewriting rules
• Mail header formats
• Options
• Security precautions
• Spam resistance
The raw config file format was designed to be easy to parse. This focus has made it a bit lacking in warm, user-friendly features. Maintenance of the config file is the most significant administrative chore related to electronic mail and scares the pejeebers out of