Dovecot/Amavis 重启脚本(进行中)

Dovecot/Amavis restart script (work in progress)

我们有一台快要死了的邮件服务器,在停用之前正在将帐户迁移到新服务器。在 25 个以上的域中拥有 800 多个电子邮件帐户,这台机器在迁移完成之前保持运行非常重要。

最近它开始充满错误日志,由于没有 space 而冻结 mysql,停止邮件流,通常让我很头疼。在找到并修复错误的根本问题之前,我想出了一个脚本来检查 Dovecot 和 Amavis-new 是否 运行,如果不是则重新启动它们。

看完后:

除了其他一些常见的例子,我还想到了这个。

netstat -an|grep -ce ':993.*LISTEN' >/dev/null 2>&1

if [ $? = 0 ]
then
    echo 'Dovecot is up';
else
    echo 'Dovecot is down, restarting...';
        /etc/init.d/dovecot restart
        logger -p mail.info dovecot_keepalive: Dovecot is down, restarting...
fi

/etc/init.d/amavis status |grep -ce 'running' >/dev/null 2>&1

if [ $? = 0 ]
then
    echo 'AmavisD is up';
else
    echo 'AmavisD is down, restarting...';
    /etc/init.d/amavis restart
    sleep 2
    /etc/init.d/amavis status |grep -ce 'running' >/dev/null 2>&1
        if [ $? = 1 ]
        then
            echo 'AmavisD had a problem restarting, trying to fix it now...';
            logger -p mail.info amavis_keepalive: AmavisD had a problem restarting...
            output=$(ps aux|grep a\[m\]avisd)
            set -- $output
            pid=
            kill $pid
            rm /var/run/amavis/amavisd.pid
            /etc/init.d/amavis start
        else
            echo 'AmavisD restarted successfully';
            logger -p mail.info amavis_keepalive: AmavisD is down, restarting...
        fi
fi

谁知道呢,我可能让事情变得更难了,如果是的话请告诉我!!!

我根据它的调试报告对照 http://www.shellcheck.net 和 updated/corrected 检查了它。我正在从其他地方的示例中将其拼凑在一起,并希望有人在我实施之前对其进行校对。

第一部分检查 dovecot 已经作为 cronjob 每 6 小时工作得很好(是的,服务器搞砸了我们需要检查它),这是关于 amavis 的部分我不确定。

您可以使用 Monit 来监控您的服务并自行重启。

阿玛维斯:

# File: /etc/monit.d/amavisd
# amavis
check process amavisd with pidfile /var/amavis/amavisd.pid
   group services
   start program = "/etc/init.d/amavisd start"
   stop  program = "/etc/init.d/amavisd stop"
   if failed port 10024 then restart
   if 5 restarts within 5 cycles then timeout

鸽舍:

# File: /etc/monit.d/dovecot
check process dovecot with pidfile /var/run/dovecot/master.pid
   start program = "/etc/init.d/dovecot start"
   stop program = "/etc/init.d/dovecot stop"
   group mail
   if failed host localhost port 993 type tcpssl sslauto protocol imap then restart
   if failed host localhost port 143 protocol imap  then restart
   if 5 restarts within 5 cycles then timeout
   depends dovecot_init
   depends dovecot_bin
check file dovecot_init with path /etc/init.d/dovecot
   group mail
check file dovecot_bin with path /usr/sbin/dovecot
   group mail