I oversee a few hundred Linux-based systems, and >99% of them run the typical QMail / ClamAV / SpamAssassin stack. I personally think QMail sucks, but I have written a script that usually fixes most issues (stuck queue, delayed mail, other strange issues). You could easily edit this to be compatible with cPanel-based servers, but as it stands it’s written for InterWorx-CP and servers without a control-panel system. Note that this needs BASH to run and won’t work properly due to the way the counter is incremented in regular POSIX ‘sh’.
Link: http://seanp2k.com/m.sh
It is below:
#!/bin/bash
# ----- BEING DECLARE FUNCTIONS -----
# prnt - formats and echos input
function prnt {
echo -e "\e[1;32m[ $1 ]\e[00m"
}
# killproc - uses pidof to find process name then tries to kill COUNTER number of times.
# Accepts $1 as process name and $2 as $
PROCNAME=""
function killproc {
procname=$1
counter=0
pids="$(pidof "$procname")"
while [ "$pids" ] && ((counter++ < $2)); do
if [ $counter -eq $2 ]; then
echo -e "\e[1;31m[ Couldn't kill $procname, tried $2 times. PID is $pids ]\e[00m"
else
# ----- DEBUGGING - uncomment next line -----
# ps -elf | grep -i $procname
for pid in $pids; do
echo -e "\e[1;36m[ $procname killed, PID $pid, try $counter/$2 ]\e[00m"
pkill -9 $pid
done
sleep 1
pids="$(pidof "$procname")"
echo
fi
done
}
# ----- END DECLARE FUNCTIONS -----
# ----- BEING MAIN SUB -----
prnt "Reset local and remote delivery concurrency limits"
echo 200 > /var/qmail/control/concurrencylocal
echo 200 > /var/qmail/control/concurrencyincoming
echo 200 > /var/qmail/control/concurrencyremote
prnt "Restart InterWorx-CP"
/etc/init.d/iworx restart
prnt "Restart ClamAV & SpamAssassin"
/etc/init.d/clamd stop
/etc/init.d/spamassassin stop
killproc spamd 5
killproc clamd 5
/etc/init.d/clamd start
/etc/init.d/spamassassin start
prnt "Restart POP3"
/etc/init.d/pop3 restart
prnt "Restart POP3-SSL"
/etc/init.d/pop3-ssl restart
prnt "Restart IMAP4"
/etc/init.d/imap4 restart
prnt "Restart IMAP4-SSL"
/etc/init.d/imap4-ssl restart
prnt "Restart SMTP"
svc -d /service/send /service/smtp /service/smtp2
/etc/init.d/smtp stop
/etc/init.d/smtp status
if [ "$(pidof qmail-send)" ]; then
counter=11
echo -en "\e[1;32m[ Waiting for SMTP to stop: "
while [ "$(pidof qmail-send)" ] && ((counter-- > 0)); do
echo -n "$counter.."
sleep 1
done
echo -e " ]\e[00m"
fi
/etc/init.d/smtp status
svc -k /service/send
killproc qmail-send 5
prnt "Force-send qmail message queue"
svc -u /service/send
svc -a /service/send
svc -u /service/smtp /service/smtp2
/etc/init.d/smtp start
prnt "Please ensure that SMTP and send are up"
/etc/init.d/smtp status
/var/qmail/bin/qmqtool -s
# ----- END MAIN SUB -----
exit 0;