home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeTCP/IP Network AdministrationSearch this book

10.2. Running sendmail as a Daemon

To receive SMTP mail from the network, run sendmail as a daemon during system startup. The sendmail daemon listens to TCP port 25 and processes incoming mail. In most cases, the code to start sendmail is already in one of your boot scripts. If it isn't, add it. The following command starts sendmail as a daemon:

# /usr/lib/sendmail -bd -q15m

This command runs sendmail with two command-line options. The -q option tells sendmail how often to process the mail queue. In the sample code, the queue is processed every 15 minutes (-q15m), which is a good setting to process the queue frequently. Don't set this time too low. Processing the queue too often can cause problems if the queue grows very large due to a delivery problem such as a network outage. For the average desktop system, every hour (-q1h) or half hour (-q30m) is an adequate setting.

The other option relates directly to receiving SMTP mail. The -bd option tells sendmail to run as a daemon and to listen to TCP port 25 for incoming mail. Use this option if you want your system to accept incoming TCP/IP mail.

The command-line example is a simple one. Most system startup scripts are more complex. These scripts generally do more than just start sendmail. Solaris 8 uses the /etc/init.d/sendmail script to run sendmail. First the Solaris script checks for the existence of the mail queue directory. If a mail queue directory doesn't exist, it creates one. In the Solaris 8 script, the command-line options are set in script variables. The variable MODE holds the -bd option, and the variable QUEUEINTERVAL holds the queue processing interval. In the Solaris 8 script, QUEUEINTERVAL defaults to 15m; change the value stored in the QUEUEINTERVAL variable to change how often the queue is processed. Do not change the value in the MODE variable unless you don't want to accept inbound mail. The value must be -bd for sendmail to run as a daemon and collect inbound mail. If you want to add other options to the sendmail command line that is run by the Solaris 8 script file, store those options in the OPTIONS variable.

The Red Hat /etc/rc.d/init.d/sendmail script is even more complex than the Solaris version. It accepts the arguments start, stop, restart, condrestart, and status so that the script can be used to effectively manage the sendmail daemon process. The start and stop arguments are self-explanatory. The restart argument first stops the sendmail process and then runs a new sendmail process. The condrestart argument is similar to restart except that it runs only if there is a current sendmail process running. If the sendmail daemon is not running when the script is run with the condrestart argument, the script does nothing. The status argument returns the status of the daemon, which is basically the process ID number if it is running or a message saying that sendmail is stopped if sendmail is not running.

When the Red Hat script is run with the start argument, it begins by rebuilding all of the sendmail database files. It then starts the sendmail daemon using the command-line options defined in the /etc/sysconfig/sendmail file. Like the Solaris script, the Red Hat script uses variables to set the value of the command-line options, but the variables themselves are set indirectly by values from /etc/sysconfig/sendmail file. The /etc/sysconfig/sendmail file from a default Red Hat configuration contains only two lines:

$ cat /etc/sysconfig/sendmail
DAEMON=yes
QUEUE=1h

If DAEMON is set to yes, sendmail is run with the -bd option. How often the queue is processed is determined by the value set for QUEUE. In this example, the queue is processed every hour (1h). The additional code found in most startup scripts is helpful, but it is not required to run sendmail as a daemon. All you really need is the sendmail command with the -bd option.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.