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.