我们有一个正在死亡的邮件服务器,并且在退役之前将帐户迁移到新服务器。在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的第一部分已经作为cronjob每6个小时工作正常(是的,服务器搞砸了,我们需要检查它),这是关于amavis我不确定的部分。
答案 0 :(得分:0)
您可以使用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