Additional Steps to Set up Spam Blocking (Postfix/Ubuntu)
This is a follow-up to a previous post: Installing a Spam Filter for Postfix on Ubuntu.
It's funny. I tend to expect code to speak for itself, but I write about things that are less transparent to me, as a way to learn, share, and record observations for later use...
I was getting ready for bed last night, when I received notification of an undeliverable email. It was an email I had sent to a client Friday. I had been looking forward to a fresh start to the week, with all the chaos of the blizzard and smaller emergencies that sprang up in the new year behind me. Life had other plans.
I poked around the server logs and realized Amavis had crashed and this is what was blocking incoming AND outgoing mail!
Here's a brief account of how I diagnosed and solved the issue.
The first thing I noticed in the log (/var/log/mail.log) was that ClamAV was giving errors. Seemed like a reasonable place to start looking for a problem, though I wasn't sure it was related to the issue with Amavis.
sudo less /var/log/clamav/clamav.log
The clamav log was surpsigingly empty.
sudo less /var/log/clamav/freshclam.log
ClamAV update process started at Sun Jan 12 09:35:14 2014
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 97 Recommended version: 98
DON'T PANIC! Read http://www.clamav.net/support/faq
I followed the link. Checked in apt, and there was no update for the package yet. Oh well.
I decided to focus on resending the bounced message now. I had restarted Amavis and everything seemed to be moving along again. I checked what mail was queued:
Quite a few bounced and undelivered messages...
Eeep 107 messages requeued. A lot of it looked like incoming spam, so hopefully that will just be filtered by Amavis... the sense of dread grows as I reopen Mail.
OK didn't blast 100 spams out into the world or anything. Just flooded my email with spam and a surprising number of relevant messages that had been queued... hope I didn't miss too much...
Now, I'm looking for the really important bounced message to my client:
man postcat sudo postcat -q 0123456789
I couldn't find it. Didn't show up in my sent messages in Mail. Apparently requing all the messages had worked, though it never did appear in my sent mail folder in Mail. All the other dequeued messages reappeared in the sent mail folder. I only realized it had worked after receiving a reply from the client.
While looking through the mailq output, I noticed mail to the root user was not able to be delivered. I added an alias so that messages to root would be sent to me instead.
I added root: william. Then I restarted the various mail servers.
sudo /etc/init.d/postfix restart sudo /etc/init.d/spamassassin restart sudo /etc/init.d/clamav-daemon restart sudo /etc/init.d/amavis restart
A new message in mail.log!
warning: database /etc/aliases.db is older than source file /etc/aliases
I noticed these messages were related to the delivery of messages to root:
dovecot: lda(root): Error: user root: Initialization failed: Namespace '': stat(/root/Maildir) failed: Permission denied (euid=---(nobody) egid=---(no group) missing +x perm: /root, dir owned by 0:0 mode=0700)
dovecot: lda(root): Fatal: Invalid user settings. Refer to server log for more information.
dovecot: lda(root): Error: chdir(/root) failed: Permission denied
Looking through various sources of information, I discovered that I needed to run this command to rebuild the alias index:
OK, two issues were solved, but I had another Amavis crash at the beginning of the afternoon. Time for some more snooping.
I rechecked the ClamAV log and there was now some output in it (/etc/log/clamav/clamav.log).
It didn't have enough memory! I decided to enable swap to fix it, by following the directions from DigitalOcean found here:
https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04
I followed those instructions, then restarted the server:
Everything in /var/log/mail.log looks good, no errors now. Hopefully the Amavis issue was due to low RAM as well, and will be solved by the addition of the swap file.
I'll be keeping an eye on the server to monitor health. I'm also looking for a good way to get this information in my DevOps dashboard.
Hopefully that's the end of that!