$ 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