Copyright © 2001 Paul A. Hoadley
2003-03-31
Abstract
This document describes how to configure qmail to generate separate logs for SMTP, POP3 and local delivery activity, so that Inter7's qmailmrtg7 package can generate statistics for use with MRTG. These instructions have been tested on FreeBSD 4.2R and 4.3R systems, but should work for any system on which the required ports are able to run. The information is claimed only to be sufficient—there are bound to be other ways to do it.
Table of Contents
The following software should already be installed:
qmail-1.03 (available in /usr/ports/mail/qmail
)
mrtg-2.9.11 (available in /usr/ports/net/mrtg
)
It is beyond the scope of this document to describe how to install this software, though a related document, Installing qmail under FreeBSD describes how to install qmail.
The setuidgid
and multilog
utilities are used from this package.
# cd /usr/ports/sysutils/daemontools # make install
This open source package is available from Inter7.
# cd tmp # fetch http://inter7.com/qmailmrtg7/qmailmrtg7-3.1.tar.gz # gunzip qmailmrtg7-3.1.tar.gz # tar -xvf qmailmrtg7-3.1.tar # cd qmailmrtg7-3.1 # make all # make install # rm /etc/qmail.mrtg.cfg
The last step is necessary because qmailmrtg7's Makefile
copies the sample configuration file for MRTG into /etc
, whereas it should ideally reside in /usr/local/etc/mrtg
, or, even more ideally, be appended to your existing MRTG config file, probably /usr/local/etc/mrtg/mrtg.cfg
. This step will be covered in the next section.
Create log directories under /var/log
for each of the daemons:
# cd /var/log # mkdir qmail # mkdir pop3 # mkdir smtp
You should change the default permissions on these directories if you desire more secure logs.
These changes will have been made if you have previously set up qmail according to Installing qmail under FreeBSD. If not, append the following lines to /etc/rc.conf
:
# qmail options qmail_smtp_enable="YES" qmail_pop_enable="YES" qmail_enable="YES"
The startup commands for each of the daemons started in /var/qmail/rc
need to be altered to take advantage of multilog
. HOST.DOMAIN
in the script below should be replaced by the mail server's Fully Qualified Domain Name (FQDN).
#!/bin/sh # # This script starts and stops the qmail mail functions. # # Suck in the configuration variables. if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi case "$1" in start) case ${qmail_smtp_enable} in [Yy][Ee][Ss]) # Start the qmail smtp daemon env - PATH="/var/qmail/bin:/usr/local/bin" \ tcpserver -v -H -R -x /etc/tcp.smtp.cdb \ -c200 -u82 -g81 0 25 fixcrio /var/qmail/bin/qmail-smtpd \ 2>&1 | /usr/local/bin/setuidgid qmaill \ /usr/local/bin/multilog t n100 s1000000 /var/log/smtp & echo -n " qmail-smtp" ;; esac case ${qmail_pop_enable} in [Yy][Ee][Ss]) # Start the qmail pop daemon env - PATH="/var/qmail/bin:/usr/local/bin" \ tcpserver -v -H -R -c200 0 110 \ /var/qmail/bin/qmail-popup HOST.DOMAIN \ /usr/local/bin/checkpassword /var/qmail/bin/qmail-pop3d \ Maildir 2>&1 | /usr/local/bin/setuidgid qmaill \ /usr/local/bin/multilog t n100 s1000000 /var/log/pop3 & echo -n " qmail-pop" ;; esac case ${qmail_enable} in [Yy][Ee][Ss]) # Start qmail exec env - PATH="/var/qmail/bin:$PATH" \ qmail-start ./Maildir | /usr/local/bin/setuidgid qmaill \ /usr/local/bin/multilog t n100 s1000000 /var/log/qmail & echo -n " qmail" ;; esac ;; stop) # Stop the smtp daemon smtppid=`ps -axw | grep tcpserver | grep smtp | grep -v grep | awk '{ print $1 }'` if [ "$smtppid" != "" ]; then kill $smtppid echo -n " qmail-smtp" fi # Stop the pop daemon poppid=`ps -axw | grep tcpserver | grep popup | grep -v grep | awk '{ print $1 }'` if [ "$poppid" != "" ]; then kill $poppid echo -n " qmail-pop" fi # Stop qmail qmailpid=`ps -axw | grep qmail-send | grep -v grep | awk '{ print $1 }'` if [ "$qmailpid" != "" ]; then kill $qmailpid echo -n " qmail" fi ;; *) echo "Usage: `basename $0` {start|stop}" >&2 ;; esac exit 0
Lines terminated with a \
can be entered as a single long line, but have been split here to increase readability.
The modification that you make to mrtg.cfg
will be highly dependent on how you have set up MRTG on your system. As a bare minimum, you could append the sample qmail.mrtg.cfg
to your own mrtg.cfg
:
# cd /usr/local/etc/mrtg # mv mrtg.cfg mrtg.cfg.bak # cat mrtg.cfg.bak /tmp/qmailmrtg7-3.1/qmail.mrtg.cfg > mrtg.cfg
You should, of course, manually edit the resulting file to ensure that there are no collisions between target names. Additionally, you will need to point to the newly generated HTML pages from your own site's MRTG index page.
The author of this document is Paul Hoadley. This document only describes what I did to get qmail and MRTG cooperating on some FreeBSD machines. Your mileage may vary.
Thanks to Bill Burrows for persisting with this, and showing me how to get it going.
The startup script for use in /usr/local/etc/rc.d/
is only minimally modified from Aaron Hill's excellent script first published in Installing qmail under FreeBSD.