linux - Dovecot/Amavis 重启脚本(正在进行中)

标签 linux shell scripting dovecot

我们有一个邮件服务器快要死了,在退役之前正在将帐户迁移到新服务器。该计算机拥有跨 25 个以上域的 800 多个电子邮件帐户,因此在迁移完成之前保持正常运行非常重要。

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

阅读后: https://stackoverflow.com/a/7096003/4820993

以及其他一些常见示例,我想出了这个。

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=$2
            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 进行了检查并根据其调试报告进行更新/更正。我正在从其他地方的示例中将其拼凑在一起,并且希望有人在我实现它之前对其进行校对。

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

最佳答案

您可以使用Monit它将监视您的服务并自行重新启动。

Amavisd:

# 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

关于linux - Dovecot/Amavis 重启脚本(正在进行中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29807484/

相关文章:

android - 如何正确地将Android设备添加到Linux中进行设备调试?

linux - Qmail/popuser环境权限(Linux/CentOS)

linux - 批量更改目录中的文件名 - Shell

linux - 协助通过 Powershell 脚本或其他脚本更新一组 Linux 计算机

linux - sed 适用于硬编码文件名,但不适用于包含所述文件名的变量

linux - 如何在 bash 循环中回显参数

linux - Bash 脚本文件意外结束

linux - forrtl : No space left on device

shell - 从 shell 获取终端的 X11 窗口 ID

linux - 每一行的功能是什么?