Recreate the qmail queue structure on Plesk server

First, please note, this script should ONLY be used on a Plesk server copy of qmail, it should never be used on a built-from-source install of qmail as the usernames, groups and ownership/permissions may differ on that type of install.

If you’ve ever experienced an issue with a virus infected customer, hacked php script, etc., you’ve probably experienced the issue of having tens or hundreds of thousands of junk emails fill up your qmail queue.  When that occurs, you’ll find that the directory indexes for all the queue directories grow to a very large size and your performance suffers from that point forward due to the operating system spending a lot more time reading directory indexes, even after you’ve cleaned out the junk email.

To recreate your queue structure, the following bash script will do it.  Please keep in mind that it will purge any and all undelivered email, so only run this once you’re sure your queue is empty of important emails.

# Stop qmail
/etc/rc.d/init.d/qmail stop
# Make double sure qmail is not running
killall -9 qmail-send qmail-remote

cd /var/qmail/queue/
rm -f bounce/*
rm -Rf info/*
rm -Rf intd/*
rm -Rf local/*
rm -Rf mess/*
rm -Rf remote/*
rm -Rf todo/*

for i in {0..22}
  mkdir info/$i intd/$i
  chown qmails:qmail info/$i local/$i remote/$i
  chown qmailq:qmail intd/$i mess/$i todo/$i
  chmod 700 info/$i intd/$i local/$i remote/$i
  chmod 750 mess/$i todo/$i

/etc/rc.d/init.d/qmail start

Leave a Reply

Your email address will not be published. Required fields are marked *