I’ve put together a quick workaround for a long-standing problem with my server, whereby every so often my mailserver will crash (usually every week or so). I discovered the problem relates to amavis crashing – but as yet I have not found a solution to the problem.
The shell script I’ve put together below (with the help of this) checks the status of the amavis service. If it’s down, the script will bring it back up and then restart postfix to resume deliveries.
I’d suggest running the script every 5 minutes from a cron job (use crontab -e to modify to your cron jobs).
#!/bin/bash
#
# Author: Alex Ward
# This script was created to find workaround to a problem where postfix would fail
# if amavis stopped on ISPConfig / Debian. This simple script will check the
# uptime of amavis and, if it is down, start it and then restart postfix.
# This script can be set up in a crontab.
#
# Built with help from
# http://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/
#
#
version=”1.1″
#Changelog: Implemented version number and prepared for crontab logging.
service=amavis
echo ‘==========================’
echo ‘MAILSERVER SYSTEM CHECKUP!’
echo ‘==========================’
echo ”
date
echo “Version: $version”
echo ”
echo “Checking $service status…”
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo “$service is running! No action required.”
else
echo “$service is DOWN! Rectifying this…”
/etc/init.d/$service start
postfix stop
postfix start
fi
echo ”
echo ‘=====================================================================’
echo ”
#END
You can download a copy of the script here (right click, save as).
It isn’t a solution to the problem – but until I find the solution, this will at least stop the problem from killing off mail deliveries.