#947116 doesn't start because of stale /var/run/dovecot/master.pid

Package:
dovecot-core
Source:
dovecot
Description:
secure POP3/IMAP server - core files
Submitter:
Tomas Pospisek
Date:
2019-12-21 10:54:03 UTC
Severity:
important
#947116#5
Date:
2019-12-21 09:41:08 UTC
From:
To:
inside an LXC container, that uses sysvinit-core as its
boot system, I get this after a `shutdown -r now`:

    Starting IMAP/POP3 mail server: dovecotFatal: Dovecot is already running with PID 1134 (read from /var/run/dovecot/master.pid) failed!

There is no PID 1134, so dovecot's startup script or
something should just delete that file and proceed
with startup.

#947116#10
Date:
2019-12-21 10:29:25 UTC
From:
To:
     $ cd /etc/init.d
     $ cat remove_dovecot_pid_file
     #!/bin/sh
     ### BEGIN INIT INFO
     # Provides:          remove_dovecot_pid_file
     # Required-Start:    $syslog
     # Required-Stop:
     # X-Start-Before:    dovecot
     # Default-Start:     2 3 4 5
     # Default-Stop:      0 1 6
     # Short-Description: remove dovecot pid file on start
     # Description:
     #  See
     ### END INIT INFO

     PIDFILE=/var/run/dovecot/master.pid

     # Define LSB log_* functions.
     . /lib/lsb/init-functions || exit 1

     case "$1" in
             start)
                     log_begin_msg "Removing old $PIDFILE"
                     REMOVED=no
                     if [ -e "$PIDFILE" ]; then
                             PID=`cat "$PIDFILE"`
                             # we assume that $PIDFILE contains
                             # PID only and no other nonsense
                             #
                             # retrieve the EXECUTABLE of the process
                             # currently running under the given PID
                             #
                             EXECUTABLE=`ps o comm "$PID"`
                             # if the saved PID doesn't correspond to
                             # a dovecot process then remove the
                             # PIDFILE
                             if [ "$EXECUTABLE" != "dovecot" ]; then
                                     rm "$PIDFILE"
                             fi
                     fi
                     if [ "$REMOVED" = "no" ]; then
                             log_progress_msg "(NOT removed)"
                     else
                             log_progress_msg "(removed)"
                     fi
                     log_end_msg 0
             ;;

             *)
                     true # do nothing
             ;;
     esac
     $ sudo chmod +x remove_dovecot_pid_file
     $ sudo update-rc.d remove_dovecot_pid_file defaults