UNIX System Administration Handbook - Evi Nemeth [336]
The service switch is covered in more detail in Chapter 18.
The operation of the service switch is normally transparent to other software, but sendmail likes to exert fine-grained control over its lookups and so on Solaris it reads the switch file directly. On other versions of UNIX, it uses its own personal switch configuration.
Two fields in the service switch that impact the mail system are aliases and hosts. The possible values for the hosts service are dns, nis, nisplus, and files. Support for all the mechanisms you use (except files) must be compiled into the sendmail binary before the service can be used.
The default location of the sendmail service switch is /etc/mail/service.switch, and its default contents are:
aliases files nisplus nis # if compiled with nis/nis+
hosts dns nisplus nis files
If dns is listed in the hosts entry, sendmail will look up MX records in DNS, even if NIS is listed first.
Modes of operation
You can run sendmail in several modes, selected with the -b flag. -b stands for “be” or “become” and is always used with another flag that determines the role sendmail will play. Table 19.6 lists the legal values.
Table 19.6 Command-line flags for sendmail’s major modes
a. This mode is used for debugging, so that you can see error and debugging messages.
If you expect incoming mail to arrive over the network, run sendmail in daemon mode (-bd). In this mode, sendmail listens on network port 25 and waits for work.15
When you run sendmail in daemon mode, you will usually specify the -q flag. It sets the interval at which sendmail processes the mail queue; for example, -q30m or -q1h to run the queue every thirty minutes or every hour.
sendmail normally tries to deliver messages immediately, saving them in the queue only momentarily to guarantee reliability. But if your host is too busy or the destination machine is unreachable, sendmail queues the message and tries to send it again later. sendmail forks a child process every time it processes the queue, so don’t set the queue processing time too short. RFC1123 recommends at least 30 minutes between runs. sendmail does locking, so multiple, simultaneous queue runs are safe.
sendmail reads its configuration file, sendmail.cf, only when it starts up. Therefore, you must either kill and restart sendmail or send it a HUP signal when you change the config file. sendmail creates a sendmail.pid file that contains its process ID and the command that started it. You should start sendmail with an absolute path because it reexecs itself on receipt of the HUP signal. The sendmail.pid file allows the process to be HUPed with:
# kill -HUP 'head -1 sendmail.pid'
The location of the PID file used to be a compile-time parameter, but it can now be set in the .mc config file with the confPID_FILE option:
define(confPID_FILE, '/var/run/sendmail.pid')
The default value is OS dependent but is usually /var/run/sendmail.pid for BSD systems and /etc/mail/sendmail.pid for others.
The mail queue
Mail messages are stored in the queue directory when the machine is too busy to deliver them immediately or when a destination machine is unavailable. The queue directory is usually /var/spool/mqueue and usually has owner root and mode 700.16
All messages go into the queue briefly as they come in from the user agent.
sendmail allows you to have more than one mail queue. If the mqueue directory contained subdirectories q1, q2, and q3 and you specified the queue directory to be /var/spool/mqueue/q*, then all three queues would be used. sendmail’s ability to handle multiple queues helps performance under high load.17
When a message is queued, it is saved in pieces in several different files. Each filename has a two-letter prefix that identifies the piece; then, a random ID built from sendmail’s process ID. This ID is not fixed because sendmail