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

TCP/IP Network Administration

TCP/IP Network AdministrationSearch this book
Previous: 10.1 sendmail's Function Chapter 10
Next: 10.3 sendmail Aliases

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 code is from the Slackware Linux /etc/rc.d/rc.M startup script:

# Start the sendmail daemon:
if [ -x /usr/sbin/sendmail ]; then
  echo "Starting sendmail daemon (/usr/sbin/sendmail -bd -q 15m)..."
  /usr/sbin/sendmail -bd -q 15m

First, this code checks for the existence of the sendmail program. If the program is found, the code displays a startup message on the console and runs sendmail with two command-line options. One option, 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 option ( -bd ) 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 Linux example is a simple one. Some systems have a more complex startup script. Solaris 2.5, which dedicates the entire /etc/init.d/sendmail script to starting sendmail, is a notable example. The mail queue directory holds mail that has not yet been delivered. It is possible that the system went down while the mail queue was being processed. Versions of sendmail prior to sendmail V8, such as the version that comes with Solaris 2.5, create lock files when processing the queue. Therefore lock files may have been left behind inadvertently and should be removed during the boot. Solaris checks for the existence of the mail queue directory and removes any lock files found there. If a mail queue directory doesn't exist, it creates one. The additional code found in some startup scripts is not required when running sendmail V8. All you really need is the sendmail command with the -bd option.