Repository: Mailu/Mailu

Issue:
Dovecot service takes long to start
```
docker stack ps mailu
ID                  NAME                IMAGE                              NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
yh6u3jrckt32        mailu_redis.1       redis:alpine                       prod02.usrpro.com   Running             Running 4 minutes ago                        
otpt6os15sy3        mailu_smtp.1        mailu/postfix:master               prod01.usrpro.com   Running             Running 4 minutes ago                        
artmzgamypoy        mailu_webdav.1      mailu/radicale:master              prod03.usrpro.com   Running             Running 4 minutes ago                        
x5ynw6h5ap3p        mailu_imap.1        usrpro/dovecot:workaround-lucene   prod03.usrpro.com   Running             Starting 4 minutes ago                       
n674xs649jlw        mailu_admin.1       mailu/admin:master                 prod01.usrpro.com   Running             Running 4 minutes ago                        
xrmri5cqjzqn        mailu_antivirus.1   mailu/clamav:master                prod02.usrpro.com   Running             Running 2 minutes ago                        
koiuyxlj2cpt        mailu_antispam.1    mailu/rspamd:master                prod03.usrpro.com   Running             Running 4 minutes ago                        
hdpu4gq182ha        mailu_webmail.1     mailu/rainloop:master              prod01.usrpro.com   Running             Running 4 minutes ago                        
wgqkwnz6wyxp        mailu_front.1       mailu/nginx:master                 prod01.usrpro.com   Running             Running 4 minutes ago                        
v2eznworzs0g        mailu_front.2       mailu/nginx:master                 prod02.usrpro.com   Running             Running 4 minutes ago                        
nckm82d8aryd        mailu_front.3       mailu/nginx:master                 prod03.usrpro.com   Running             Running 4 minutes ago 
```
In `start.py`, most probably it is stuck on:
```
multiprocessing.Process(target=start_podop).start()
```

Have to confirm with writing some logging, like requested in issue #588 .


Discussion:
It's probably dh-param again… :roll_eyes:
see https://wiki2.dovecot.org/SSL/DovecotConfiguration#SSL_security_settings

Quote:
> When Dovecot starts up for the first time, it generates new 512bit and 1024bit Diffie Hellman parameters and saves them into /var/lib/dovecot/ssl-parameters.dat

So dh-params get generated and saved inside the volatile container which is gone once the container is re-created
Ooh, damn. That;s a good one. It's the middle of the night and I've just given up on swarm, destroyed the stack and went back to compose, only to find out that the problem still appears (using one of the same host). Already started to suspect the VM environment of freezing up podop's asyncio.

Unfortunately I've missed this message, since I'm lucky enough this issue affects only my production servers.

Thanks for the tip. I'll look into this in the morning... 
I've mounted /var/lib/dovecot and found no generated ssh-parameters.dat. Probably because we don't use ssl in dovecot?

Instead, I found that `chown -R` is the guilty one. It is recursively changing ownership of all the mailboxes, which are stored on glusterfs. Ouch! This explains why I'm seeing this problem getting bigger over time: more mails in the mailboxes.

Easy fix though...

Resolving patch:
diff --git a/core/dovecot/start.py b/core/dovecot/start.py
--- a/core/dovecot/start.py
+++ b/core/dovecot/start.py
@@ -33,5 +33,6 @@ def start_podop():
 
 # Run Podop, then postfix
 multiprocessing.Process(target=start_podop).start()
-os.system("chown -R mail:mail /mail /var/lib/dovecot /conf")
+os.system("chown mail:mail /mail")
+os.system("chown -R mail:mail /var/lib/dovecot /conf")
 os.execv("/usr/sbin/dovecot", ["dovecot", "-c", "/etc/dovecot/dovecot.conf", "-F"])


Test patch: