Change Detection
DMS runs a change detection service (changedetector) that watches a fixed set of files and applies changes to the running services. This is why setup email add and the other setup commands that edit the config volume take effect without restarting the container.
Overview
- The service is always started, there is no ENV to disable it.
- It polls, it does not use file system notifications. The wait between two checks is
DMS_CONFIG_POLLseconds (default:2), so a change is applied a short while after it was made. - It compares the SHA-512 hashes of the monitored files. Only a change to the content of a file counts, touching a file does not.
- Only the files listed on this page are monitored. For all other files, see Other Files.
Monitored Files
Config Volume
These files in docker-data/dms/config/ (/tmp/docker-mailserver/ in the container) are monitored:
postfix-accounts.cfpostfix-virtual.cfpostfix-aliases.cfpostfix-regexp.cfpostfix-relaymap.cfpostfix-sasl-password.cfdovecot-quotas.cfdovecot-masters.cf- Every file in the
rspamd/directory (only withENABLE_RSPAMD=1)
A file that does not exist is skipped. When it is created later, that counts as a change.
TLS Certificates
- With
SSL_TYPE=manual: the files thatSSL_CERT_PATH,SSL_KEY_PATH,SSL_ALT_CERT_PATHandSSL_ALT_KEY_PATHpoint to. - With
SSL_TYPE=letsencrypt:/etc/letsencrypt/acme.json(the certificate store of Traefik) and the*.pemfiles in/etc/letsencrypt/live/<NAME>/, where<NAME>is each ofSSL_DOMAIN, the FQDN of the container (mail.example.com) and its domain name (example.com).
What Happens on a Change
At the end of the container setup, DMS stores the hash of each monitored file. A change is detected when a hash differs from the stored one (or is new). Then the service logs Change detected, applies the changes below, and stores the new hashes.
| Changed file | What DMS applies |
|---|---|
postfix-accounts.cf, postfix-virtual.cf |
The managed domains (/etc/postfix/vhost), the Dovecot and Postfix accounts, the virtual aliases, the relay config |
postfix-aliases.cf |
The Dovecot and Postfix accounts, the system aliases (/etc/aliases) |
postfix-regexp.cf |
The regexp aliases |
dovecot-quotas.cf, dovecot-masters.cf |
The Dovecot and Postfix accounts |
postfix-relaymap.cf, postfix-sasl-password.cf |
The relay config |
Files in rspamd/ |
A change in override.d/ or to custom-commands.conf rebuilds /etc/rspamd/override.d/: its contents are replaced with override.d/, and custom-commands.conf is applied on top. Then Rspamd is reloaded |
Certificate files of SSL_TYPE=manual |
The certificates are copied to the directory that Postfix and Dovecot use |
acme.json |
The certificate is extracted from it |
Every detected change ends with a reload of Postfix and (unless SMTP_ONLY=1) Dovecot. With ENABLE_AMAVIS=1, Amavis is reloaded too when the managed domains changed. Changed .pem files in /etc/letsencrypt/live/ (without acme.json) only trigger these reloads.
ACCOUNT_PROVISIONER=LDAP
With the LDAP provisioner only the TLS certificates and the rspamd/ files are handled (plus the reloads). The accounts, aliases and relay config of the table above are not processed, as the accounts are not managed through these files.
Other Files
Changes to files that are not monitored, like postfix-main.cf, postfix-master.cf, dovecot.cf or user-patches.sh, are only applied when a new container starts. Restarting an existing container skips most of the setup, so recreate it (for example with docker compose up -d --force-recreate).
Logs
The service writes to its own log file:
docker exec <CONTAINER NAME> tail -f /var/log/supervisor/changedetector.log
Change detectedis logged at the defaultLOG_LEVEL=info.LOG_LEVEL=debugalso logs when the services are reloaded and when the handling of the change completed.LOG_LEVEL=tracealso logs which parts of the config are regenerated, likeRegenerating accounts (Dovecot + Postfix).
Limitations
- Deleting a monitored file is detected, and the services are reloaded, but nothing that is derived from the file is regenerated. Empty the file instead of deleting it, or recreate the container.
- The files written by
setup email restrict(postfix-send-access.cfandpostfix-receive-access.cf) are not monitored.
Technical Details
- The service is the script
check-for-changes.sh, which is started bysupervisord. The monitored files are listed inchange-detection.sh. - While the service applies a change, it holds the lock file
check-for-changes.sh.lockin the config volume. Containers that share a config volume therefore do not apply changes at the same time. A lock that is older than one minute is considered stale and removed.