Qmail notes

From Noah.org
Revision as of 18:36, 10 September 2008 by Root (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is for a Qmailrocks install. This may not work on other qmail installations. Or it may work. Or it may screw up up your mail queue; or your qmail installation; or your whole machine; or your friend's machines; or distort the fabric of space and time. That is the beauty of qmail.

handy third-party tools

qmail Information by John M. Simpson. In particular, qfixq can be helpful.

qmHandle by Michele Beltrame

qmail.sh

This is a qmail control script. It's crude, but it works. Note that this won't fix queue problems. Look for the qfixq script.

Note the "spamon" and "spamoff" commands. These are useful for turning just spam/virus filtering off. Sometimes spamassassin or clamav get messed up and it is preferable to get mail back online without spam/virus filtering while you try to figure out the problem.

#! /bin/sh
# Start or stop all mail services.
# Intended for a standard Qmail Rocks installation.
# Noah

case $1 in
status)
    echo "=== clamav ================================================="
    #/etc/init.d/clamd status
    ps auxww | grep clamd | grep -v "grep clamd"
    echo "=== spamassassin ==========================================="
    #/etc/init.d/spamd status
    ps auxww | grep spamd | grep -v "grep spamd"
    echo "=== imap ==================================================="
    ps auxww | grep imap | grep -v "grep imap"
    echo "=== authdaemond ============================================"
    # Wish I could do "/usr/local/sbin/authdaemond status"
    ps auxww | grep authdaemond | grep -v "grep authdaemond"
    echo "=== readproctitle =========================================="
    ps auxww | grep readproctitle | grep -v "grep readproctitle"
    echo "=== qmailctl ==============================================="
    /usr/bin/qmailctl stat
    echo "=== /var/log/maillog ======================================="
    tail /var/log/maillog
    echo "=== /var/log/qmail/qmail-send/current ======================"
    tail /var/log/qmail/qmail-send/current
    echo "=== /var/log/qmail/qmail-smtpd/current ====================="
    tail /var/log/qmail/qmail-smtpd/current
    echo "============================================================"
    ;;
spamon)
    cp /var/qmail/supervise/qmail-smtpd/run /var/qmail/supervise/qmail-smtpd/run.backup
    sed -i -e "s/^#QMAILQUEUE=.*/QMAILQUEUE=\"\/var\/qmail\/bin\/qmail-scanner-queue.pl\" ; export QMAILQUEUE/g" /var/qmail/supervise/qmail-smtpd/run
    ;;
spamoff)
    cp /var/qmail/supervise/qmail-smtpd/run /var/qmail/supervise/qmail-smtpd/run.backup
    sed -i -e "s/^QMAILQUEUE=.*/#QMAILQUEUE=\"\/var\/qmail\/bin\/qmail-scanner-queue.pl\" ; export QMAILQUEUE/g" /var/qmail/supervise/qmail-smtpd/run
    ;;
start)
    # Without this clamd won't start up sometimes
    # (clamd.log ownership gets messed up).
    #    ERROR: Problem with internal logger. Please check the permissions on the /var/log/clamav/clamd.log file.
    # I'm not sure what causes this, but this hack fixes it and
    # is probably harmless on systems that don't have this problem.
    chown `grep ^User /etc/clamd.conf | cut -d ' ' -f2` /var/log/clamav/*
    /usr/local/sbin/authdaemond start
    /etc/init.d/clamd start
    /etc/init.d/spamd start
    /etc/init.d/imap start
    /etc/init.d/imaps start
    svc -u /service/qmail-pop3d
    svc -u /service/qmail-smtpd
    svc -u /service/qmail-send
    /usr/bin/qmailctl start
    ;;
stop)
    /usr/bin/qmailctl stop
    svc -d /service/qmail-send
    svc -d /service/qmail-smtpd
    svc -d /service/qmail-pop3d
    /etc/init.d/imaps stop
    /etc/init.d/imap stop
    /etc/init.d/spamd stop
    /etc/init.d/clamd stop
    /usr/local/sbin/authdaemond stop
    ;;
lsq)
    find /var/qmail/queue -type f -exec ls -l {} \;
    ;;
*)
    cat <<HELPHERE
$0 COMMAND
status --- Show status of all mail services.
spamon  -- Enable spam/virus filtering in /var/qmail/supervise/qmail-smtpd/run.
spamoff -- Disable spam/virus filtering.
start ---- Start all mail services.
stop ----- Stop al mail services.
lsq ------ List all files in qmail queue folders.
HELPHERE
    ;;
esac
exit 0

Shell command aliases

Add this to your bash aliases.

alias lsq='find /var/qmail/queue -type f -exec ls -l {} \;'

User Aliases

Why isn't this documented properly? Maybe this is still an experimental command. At any rate, I had to try both way just to figure out which comes first in the argument list. This creates a new addres, alias_user@example.com. All mail sent to alias_user@example.com will get put in the mailbox for real_user@example.com.

/home/vpopmail/bin/valias -i real_user@example.com alias_user@example.com

alert: cannot start: unable to open mutex

Looking at the log file, /var/log/qmail/qmail-send/current, shows lots of "alert: cannot start: unable to open mutex" error messages. I don't know how this happened. I had shutdown qmail. Maybe I had done a hard reboot of the machine. I don't remember. Oh, good grief! Why don't I stop complaining and ditch qmail? No amount of "perfection" is worth the hassle of this thing. Only autistic savants could love qmail. At any rate, this fixed the problem (Yeah, this is obvious, right?):

qmailctl stop
touch /var/qmail/queue/lock/sendmutex
chown qmails:qmail /var/qmail/queue/lock/sendmutex
qmailctl start

qmail-tcpok: fatal: unable to write /var/qmail/queue/lock/tcpto: file does not exist

Again, this is another annoying error for which I haven't the slightly clue as to the cause. If you get this when running `qmail-tcpok` then this seems to fix it:

qmailctl stop
touch /var/qmail/queue/lock/tcpto
chown qmails:qmail /var/qmail/queue/lock/tcpto
qmailctl start

Purge queue -- useful for double-bounce mail bomb cleanup

I got hit with an explosion of double-bounce messages. I didn't want to just purge my entire queue of unprocessed messages. There is a script called qmHandle that will let you delete messages from the queue based on a RegEx match against the contents of the message. In the case of a double-bounce failure message the Subject line will be "failure notice". Run qmHandle like this:

./qmHandle -S'failure notice'

or like this:

./qmHandle -H'^Subject: failure notice$'

Or could also look for the "From:" line:

./qmHandle -H'^From: MAILER-DAEMON@mail.example.com$'

Note that this will temporarily shutdown qmail. The script may pause for a long time as it must wait for qmail to stop which waits for all current operations to finish and close network connections.

another way

You can use qmail-remove remove emails from the queue. Be sure to stop qmail first: 'qmailctl stop'. Example to remove double bounces where mail.example.com should be your host's FQDN:

qmail-remove -f -i -v -q /var/qmail/queue -p MAILER-DAEMON@mail.example.com

ignore double-bounce messages

This creates a dummy alias called bitbucket that does not receive mail then makes that address the one that qmail sends doublebounce notices to.

echo '#' > /var/qmail/alias/.qmail-bitbucket
echo bitbucket > /var/qmail/control/doublebounceto

Uh-oh:_.qmail_has_prog_delivery_but_has_x_bit_set._(#4.7.0)

This should fix it:

find /home/vpopmail -name ".qmail*" -exec chmod 600 {} \; -print

Uh-oh:_home_directory_is_writable._(#4.7.0)

Home directory may refer to both /home/vpopmail/domains and /home/USERNAME:

chmod -R go-rwx /home/vpopmail/domains/
chmod -R og-w /home/USERNAME