Running Dovecot

August 14, 2022 by Roberto Puzzanghera 2 comments

I have adjusted the startup script distributed by Dovecot and saved it as /usr/local/bin/dovecotctl:

#!/bin/bash

### BEGIN INIT INFO
# Provides:          dovecot
# Required-Start:    $local_fs $remote_fs $network $syslog $time
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      postgresql mysql slapd winbind
# Should-Stop:       postgresql mysql slapd winbind
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Dovecot init script
# Description:       Init script for dovecot services
### END INIT INFO

# Example /etc/init.d/dovecot script. Change DAEMON if necessary.
# License is public domain.

DAEMON=/usr/local/dovecot/sbin/dovecot

# Uncomment to allow Dovecot daemons to produce core dumps.
#ulimit -c unlimited

test -x $DAEMON || exit 1
set -e

base_dir=`$DAEMON config -h base_dir`
pidfile=$base_dir/master.pid

if test -f $pidfile; then
  running=yes
else
  running=no
fi

case "$1" in
  start)
    echo -n "Starting Dovecot"
    $DAEMON
    echo "."
    ;;
  stop)
    if test $running = yes; then
      echo "Stopping Dovecot"
      kill `cat $pidfile`
      echo "."
    else
      echo "Dovecot is already stopped."
    fi
    ;;
  reload)
    if test $running = yes; then
      echo -n "Reloading Dovecot configuration"
      kill -HUP `cat $pidfile`
      echo "."
    else
      echo "Dovecot isn't running."
    fi
    ;;
  restart|force-reload)
    echo -n "Restarting Dovecot"
    if test $running = yes; then
      kill `cat $pidfile`
      sleep 1
    fi
    $DAEMON
    echo "."
    ;;
  *)
    echo "Usage: dovecotctl {start|stop|reload|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0
wget -O /usr/local/bin/dovecotctl https://notes.sagredo.eu/files/qmail/dovecot/dovecotctl
chmod +x /usr/local/bin/dovecotctl

Run Dovecot and that's what you should see:

> dovecotctl
Usage: dovecotctl {start|stop|reload|restart|force-reload}

> dovecotctl start
Starting Dovecot.

> ps axfu
root       164  0.0  0.0   4692  2940 ?        Ss   Jul29   0:06 /usr/local/dovecot/sbin/dovecot 
dovecot    167  0.0  0.0   4356  1148 ?        S    Jul29   0:01  \_ dovecot/anvil 
root       168  0.0  0.0   4616  2968 ?        S    Jul29   0:01  \_ dovecot/log 
root       169  0.0  0.0   7888  4796 ?        S    Jul29   0:06  \_ dovecot/config 
dovecot    344  0.0  0.0   6084  3112 ?        S    Jul29   0:04  \_ dovecot/stats 
vpopmail 16052  0.0  0.0   8760  6900 ?        S    17:26   0:00  \_ dovecot/imap-login 
dovecot  16053  0.0  0.0  10820  7744 ?        S    17:26   0:00  \_ dovecot/auth 
dovecot  16054  0.0  0.0  10836  7452 ?        S    17:26   0:00  \_ dovecot/auth -w 
vpopmail 16055  0.0  0.0  44276  9340 ?        S    17:26   0:00  \_ dovecot/imap

Running Dovecot at boot time

To run Dovecot at boot time simply add a line like this into your rc.local.

/usr/local/bin/dovecotctl start &

If you are in a systemd OS the rc.local file will be saved in /etc/rc.local and you'll have to instruct systemd to launch it at boot. To recall how to do you are invited to have a look at this comment below (tx GoofY).

It is important to setup the rc.local because all the services from now on will be launched at boot time by this script and not by daemontools.

Dovecot under daemontools

If you want to run Dovecot under daemontools look here.

Comments

Creating a rc.local for systemd

Hi,

Most current Linux systems don't come with a rc.local anymore, to circumvent:

nano /etc/systemd/system/rc-local.service

--------------------
[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
---------------

Then:

nano /etc/rc.local

--------------------
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/usr/local/bin/dovecotctl start &

exit 0:
---------------

chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service

Reply |

dovecot under daemontools

It would be even better to use "daemontools" we all love, for the supervision of dovecot IMAP server.

Roberto will definitely want to offer this setup as an alternative to "dovecotctl" script above :-)

Setup is as follows:

1. Create supervise script folders as usual:

mkdir -P /var/qmail/supervise/dovecot/log

2. Create /var/qmail/supervise/dovecot/run script and add:

#!/bin/sh
exec /usr/local/dovecot/sbin/dovecot -F 2>&1

3. Create /var/qmail/supervise/dovecot/log/run script and add:

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s16000000 n200 /var/log/qmail/dovecot

4. Create dovecot log directory as usual and arrange permissions:

mkdir -P /var/log/qmail/dovecot
chown -R qmaill:nofiles /var/log/qmail/dovecot

5. Edit /usr/local/dovecot/etc/dovecot/conf.d/10-logging.conf and make sure that dovecot logs to /dev/stderr,

which will be collected under the log folder we created in step 4:

#log_path = syslog
log_path = /dev/stderr

6- Adjusting qmailctl script for the new setup is pretty easy: Just move the "dovecot" from "servicelist" to "svc list":

# Put here the services you want to manage
svclist="qmail-smtpd qmail-smtpsd qmail-submission qmail-send vpopmaild dovecot"
# Put here the services want monitoring
servicelist="clamd freshclam spamd vusaged httpd mariadb fail2ban"

7. Create the symbolic under link under /service and enjoy :-)

ln -s /var/qmail/supervise/dovecot /service/dovecot

Reply |

Recent comments
See also...
Recent posts

RSS feeds