8ad5d0
diff -up dovecot-2.3.15/dovecot-init.service.initbysystemd dovecot-2.3.15/dovecot-init.service
8ad5d0
--- dovecot-2.3.15/dovecot-init.service.initbysystemd	2021-06-21 20:21:49.250680889 +0200
8ad5d0
+++ dovecot-2.3.15/dovecot-init.service	2021-06-21 20:21:49.250680889 +0200
8f30fd
@@ -0,0 +1,13 @@
8f30fd
+[Unit]
8f30fd
+Description=One-time Dovecot init service
8f30fd
+ConditionPathExists=|!/etc/pki/dovecot/certs/dovecot.pem
8f30fd
+
8f30fd
+[Service]
8f30fd
+Type=oneshot
8f30fd
+RemainAfterExit=no
8f30fd
+ExecStart=/bin/sh -c '\
8f30fd
+if [ ! -f /etc/pki/dovecot/certs/dovecot.pem ]; \
8f30fd
+then\
8f30fd
+  SSLDIR=/etc/pki/dovecot/ OPENSSLCONFIG=/etc/pki/dovecot/dovecot-openssl.cnf /usr/libexec/dovecot/mkcert.sh /dev/null 2>&1;\
8f30fd
+fi'
8f30fd
+
8ad5d0
diff -up dovecot-2.3.15/dovecot.service.in.initbysystemd dovecot-2.3.15/dovecot.service.in
8ad5d0
--- dovecot-2.3.15/dovecot.service.in.initbysystemd	2021-06-21 20:21:49.250680889 +0200
8ad5d0
+++ dovecot-2.3.15/dovecot.service.in	2021-06-21 20:22:46.935981920 +0200
8ad5d0
@@ -11,7 +11,8 @@
8f30fd
 Description=Dovecot IMAP/POP3 email server
8f30fd
 Documentation=man:dovecot(1)
8ad5d0
 Documentation=https://doc.dovecot.org/
8f30fd
-After=local-fs.target network-online.target
8f30fd
+After=local-fs.target network-online.target dovecot-init.service
8f30fd
+Requires=dovecot-init.service
8f30fd
 
8f30fd
 [Service]
8ad5d0
 Type=@systemdservicetype@
8ad5d0
diff -up dovecot-2.3.15/Makefile.am.initbysystemd dovecot-2.3.15/Makefile.am
8ad5d0
--- dovecot-2.3.15/Makefile.am.initbysystemd	2021-06-21 20:21:49.250680889 +0200
8ad5d0
+++ dovecot-2.3.15/Makefile.am	2021-06-21 20:24:26.676765849 +0200
8ad5d0
@@ -21,6 +21,7 @@ EXTRA_DIST = \
8ad5d0
 	run-test-valgrind.supp \
8ad5d0
 	dovecot.service.in \
8ad5d0
 	dovecot.socket \
8ad5d0
+	dovecot-init.service \
8ad5d0
 	$(conf_DATA)
8f30fd
 
8ad5d0
 noinst_DATA = dovecot-config
8ad5d0
@@ -69,7 +70,8 @@ dovecot-config: dovecot-config.in Makefi
8ad5d0
 if WANT_SYSTEMD
8f30fd
 systemdsystemunit_DATA = \
8f30fd
         dovecot.socket \
8f30fd
-        dovecot.service
8f30fd
+        dovecot.service \
8f30fd
+        dovecot-init.service
8f30fd
 endif
8f30fd
 
8f30fd
 install-exec-hook: