From d04aceccae66bda8b988427601439be6ac28e076 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Sun, 5 Jun 2022 12:02:25 +1200 Subject: [PATCH] fix: Only add state of enabled services for volume mount (#2608) * fix: Conditionally add service state These services will no longer copy over state unless they are enabled. The biggest offender here was ClamAV as it's database that is baked into the docker image is over 200MB and would copy over to every container instance with a volume mounted state directory. * chore: Add Dovecot to conditional support --- target/scripts/startup/misc-stack.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/target/scripts/startup/misc-stack.sh b/target/scripts/startup/misc-stack.sh index e88d358d..584d26db 100644 --- a/target/scripts/startup/misc-stack.sh +++ b/target/scripts/startup/misc-stack.sh @@ -24,14 +24,17 @@ function _misc_save_states FILES=( spool/postfix lib/postfix - lib/amavis - lib/clamav - lib/spamassassin - lib/fail2ban - lib/postgrey - lib/dovecot ) + # Only consolidate state for services that are enabled + # Notably avoids copying over 200MB for the ClamAV database + [[ ${ENABLE_AMAVIS} -eq 1 ]] && FILES+=('lib/amavis') + [[ ${ENABLE_CLAMAV} -eq 1 ]] && FILES+=('lib/clamav') + [[ ${ENABLE_FAIL2BAN} -eq 1 ]] && FILES+=('lib/fail2ban') + [[ ${ENABLE_SPAMASSASSIN} -eq 1 ]] && FILES+=('lib/spamassassin') + [[ ${ENABLE_POSTGREY} -eq 1 ]] && FILES+=('lib/postgrey') + [[ ${SMTP_ONLY} -ne 1 ]] && FILES+=('lib/dovecot') + for FILE in "${FILES[@]}" do DEST="${STATEDIR}/${FILE//\//-}" @@ -55,10 +58,11 @@ function _misc_save_states done _log 'trace' 'Fixing /var/mail-state/* permissions' - chown -R clamav /var/mail-state/lib-clamav + [[ ${ENABLE_CLAMAV} -eq 1 ]] && chown -R clamav /var/mail-state/lib-clamav + [[ ${ENABLE_SPAMASSASSIN} -eq 1 ]] && chown -R debian-spamd /var/mail-state/lib-spamassassin + [[ ${ENABLE_POSTGREY} -eq 1 ]] && chown -R postgrey /var/mail-state/lib-postgrey + chown -R postfix /var/mail-state/lib-postfix - chown -R postgrey /var/mail-state/lib-postgrey - chown -R debian-spamd /var/mail-state/lib-spamassassin # UID = postfix(101): active, bounce, corrupt, defer, deferred, flush, hold, incoming, maildrop, private, public, saved, trace # UID = root(0): dev, etc, lib, pid, usr