2015-04-22 35 views
-1

我們有一個郵件服務器正在死亡,並且正在將帳戶在退役之前遷移到新服務器。通過超過25個域名的超過800個電子郵件帳戶,重要的是這臺機器保持運行直到遷移完成。Dovecot/Amavis重啓腳本(工作正在進行)

最近它已經開始填滿錯誤日誌,它會因爲沒有空間而凍結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我不確定的部分。

+0

要監視的服務,你應該使用'monit'如果失敗http://mmonit.com/monit/ – Satish

回答

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 
+0

感謝這將重新啓動的服務!我會研究一下。無論如何,這更多是shell腳本的實驗 - 我從來沒有在Linux中完成過。 –

+0

'monit'非常受流行守護進程的支持,它支持多種檢查服務的方式,並且與shell腳本相比更具可配置性 – Satish

相關問題