Hello. The dovecot service periodically hangs on the server, causing IMAP to stop working. I am trying to automatically restart the service when it hangs. I found an example for FreeBSD:

*/5 * * * * /usr/bin/find /usr/local/etc/rc.d/ -type file | xargs -I$ sh -c "($ 2>&1 | grep -q -v status) \ && exit ; ($ status > /dev/null) && exit ; $ start" 

Help to do likewise for Debian. Thanks in advance.

    1 answer 1

    Firstly, the above script has no relation to the dovecot program - it checks the status of all demons whose start-stop scripts are in the specified directory (it is clear that, according to the lsb standards , this will be the /etc/init.d directory, and not /usr/local/etc/rc.d , as in the example).

    for one demon, the full analogue of the script you found will be as follows:

     # /etc/init.d/dovecot status >/dev/null || /etc/init.d/dovecot start 

    secondly, it just launches daemons whose start-stop scripts have the status parameter and, when called with this parameter, return a non-zero result. i.e., triggers idle demons.

    if your dovecot program really stops working, then such a script will do. and if, as you wrote, the program “freezes” (as I understand it, the program continues to run, but does not respond to network requests), then this script will not help - after all, you need to check not the availability of the process (s), but its operation.


    the most correct answer, from my point of view: it is necessary to identify and eliminate the causes of the “freeze”, and not to correct their consequences.

    • If the program stops responding to network requests - then there may be a reason to make a timeout, and if during this time the answer has not come, do /etc/init.d/dovecot stop &&!: 0 start ?? - Crystal
    • @Crystal, do ... - yes, and in short, just restart. - aleksandr barakin