Administration
Running a mail server is an ongoing task. You cannot start it and forget about it. There are periodic administrative tasks, and you should regularly check for any problems your system might have. This section discusses many of those tasks and how to accomplish them with Postfix.
Postfix provides a utility through the postfix command to validate many aspects of your installation. The command checks for configuration problems, looks at directory and file ownership, and creates any missing directories. Executing:
# postfix check
should report no messages on a correctly installed system. If there are any problems, the command reports them to you both on the screen and in your log file.
Logging
Since Postfix is a long-running program, you should regularly check your system’s log file for warnings or messages. Things can change on your system that might impact Postfix. Almost all Postfix activity, successful or not, is logged. Whenever you start or reload Postfix, it is a good idea to check your log file for messages.
Postfix logging is accomplished by using your system’s syslog daemon. System log files are an aspect of system administration that vary across versions of Unix, so you may have to consult your own system documentation to fully understand Postfix logging.
In general, the syslog daemon (syslogd
) receives messages from various
system processes and writes them to their final destination (often a
file). syslogd
organizes messages
according to their importance and the application or facility that
generated the message. The file /etc/syslog.conf tells syslogd
where to write each type of message.
The logging facility used by Postfix is mail
. If you don’t know where to find messages logged by
Postfix, the file /etc/syslog.conf should point you in the
right direction. Some operating systems, by convention, log nearly
everything to a single file, such as /var/log/syslog, while others prefer to
separate messages by applications or services, so that Postfix
messages go to a file like /var/log/maillog. For the latter type of
systems, you might find an entry like the following in /etc/syslog.conf:
mail.* -/var/log/maillog
Once you locate your mail log file, check it regularly. You’ll probably want to check it at least daily, but decide for yourself, depending on the volume of mail your server handles and your existing log rotation scheme. You can use the following command to find Postfix messages that might be of interest:
$ egrep '(reject|warning|error|fatal|panic):' /var/log/maillog
assuming that your log file is /var/log/maillog. If not, substitute the name of your own mail log file.
Starting, Stopping, and Reloading Postfix
You saw earlier in the chapter how to use the postfix command to start Postfix:
# postfix start
Once Postfix is running, if you make any changes to main.cf or master.cf, have Postfix reread its configuration by executing postfix with the reload argument:
# postfix reload
Postfix gracefully terminates running processes after they have finished any tasks they are working on, rereads its configuration files, and continues to receive mail without interruption.
The most important thing when starting or reloading Postfix is to check your system log to see if Postfix reports any errors or warnings.
You can stop Postfix with the stop argument. Running processes will still finish any tasks they’re working on and then terminate:
# postfix stop
You should not stop and start Postfix when a reload will suffice. Also, do not stop, restart, or reload frequently, since any of these actions can impact performance.
Running Postfix at System Startup
Most systems automatically start Postfix when they boot up because of Postfix’s built-in Sendmail compatibility. Sendmail is typically launched at startup with a command like:
sendmail -bd -q15m
The Postfix sendmail
command understands nearly all of the same options as
Sendmail, so if your server already has scripts that start Sendmail,
those same scripts will start Postfix. One common Sendmail option
ignored by Postfix is -q
, which is used by Sendmail to specify the time between
queue scans. The time between queue scans for Postfix is set in the
main.cf file with the queue_run_delay
parameter, which defaults to 1000 seconds.
Your system may have a configuration option to turn on automatic startup of Sendmail. After you install Postfix, turning on this option should be sufficient to cause Postfix to start at system initialization. Different versions of Unix have different idioms for configuring a server to start a process at system initialization. If your system’s Sendmail start script doesn’t work, or you prefer to use a Postfix-specific script, you can easily create a start script.
Do it yourself
The requirements and conventions for initialization scripts vary among the different versions of Unix, so you should consult your system’s documentation to see where and how to add startup options. On System V-type systems, you can install a script like the one shown in Example 4-1.
#!/sbin/sh # # Set the path to your own logger and postfix commands. # LOGGER="/usr/bin/logger" POSTFIX="/usr/sbin/postfix" rc=0 if [ ! -f $POSTFIX ] ; then $LOGGER -t $0 -s -p mail.err "Unable to locate Postfix" exit(1) fi if [ ! -f /etc/postfix/main.cf ] ; then $LOGGER -t $0 -s -p mail.err "Unable to locate Postfix configuration" exit(1) fi case "$1" in start) echo -n "Starting Postfix" $POSTFIX start rc=$? echo "." ;; stop) echo -n "Stopping Postfix" $POSTFIX stop rc=$? echo "." ;; restart) echo -n "Restarting Postfix" $POSTFIX reload rc=$? echo "." ;; *) echo "Usage: $0 {start|stop|restart}" rc=1 esac exit $rc
Depending on your environment, you may also want to add additional pre- and post-checks to this example. You should install your script in the correct directory for your system, commonly /etc/init.d, although HP-UX, for example, uses /sbin/init.d. Once the script is in place, you also have to create a symlink to it in the appropriate run level directory for your server (often /etc/rc2.d). For example, if you named the above script postfix, create a symlink such as the following:
# ln -s /etc/init.d/postfix /etc/init.d/rc2.d/S95postfix
You should consult your system documentation for the details on your platform.
Queue Management
The Postfix queue is also an important part of email administration. See Chapter 5 for information on the Postfix queue manager.
Get Postfix: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.