From 4872d0e777dc9a61f82cc1711df851818dd86fee Mon Sep 17 00:00:00 2001 From: Kyle Ondy Date: Thu, 4 Aug 2016 15:04:26 -0400 Subject: [PATCH] selective service disable (#250) * Allow disabling amavis service Setting the `DISABLE_AMAVIS=1` env var will skip the starting of the amavis process. * Enable option to not run spamassassin Setting the `DISABLE_SPAMASSASSIN=1` env var will start this container without spamassain. * Allow starting of the container without clamav Setting the `DISABLE_CLAMAV=1` env var will start this container without starting clamav. --- Makefile | 20 +++++++++++++++++++- target/start-mailserver.sh | 12 +++++++++--- test/tests.bats | 15 +++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b2f97842..c8bd2498 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,24 @@ run: -e ENABLE_FAIL2BAN=1 \ --cap-add=NET_ADMIN \ -h mail.my-domain.com -t $(NAME) + sleep 20 + docker run -d --name mail_disabled_amavis \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test":/tmp/docker-mailserver-test \ + -e DISABLE_AMAVIS=1 \ + -h mail.my-domain.com -t $(NAME) + sleep 20 + docker run -d --name mail_disabled_spamassassin \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test":/tmp/docker-mailserver-test \ + -e DISABLE_SPAMASSASSIN=1 \ + -h mail.my-domain.com -t $(NAME) + sleep 20 + docker run -d --name mail_disabled_clamav \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test":/tmp/docker-mailserver-test \ + -e DISABLE_CLAMAV=1 \ + -h mail.my-domain.com -t $(NAME) # Wait for containers to fully start sleep 20 @@ -77,4 +95,4 @@ tests: clean: # Remove running test containers - docker rm -f mail mail_pop3 mail_smtponly mail_fail2ban fail-auth-mailer + docker rm -f mail mail_pop3 mail_smtponly mail_fail2ban fail-auth-mailer mail_disabled_amavis mail_disabled_spamassassin mail_disabled_clamav diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 31bdae72..037332f9 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -326,9 +326,15 @@ if [ -f /tmp/docker-mailserver/dovecot.cf ]; then fi # Start services related to SMTP -/etc/init.d/spamassassin start -/etc/init.d/clamav-daemon start -/etc/init.d/amavis start +if ! [ "$DISABLE_SPAMASSASSIN" = 1 ]; then + /etc/init.d/spamassassin start +fi +if ! [ "$DISABLE_CLAMAV" = 1 ]; then + /etc/init.d/clamav-daemon start +fi +if ! [ "$DISABLE_AMAVIS" = 1 ]; then + /etc/init.d/amavis start +fi /etc/init.d/opendkim start /etc/init.d/opendmarc start /etc/init.d/postfix start diff --git a/test/tests.bats b/test/tests.bats index 724a3058..f19a8542 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -37,6 +37,21 @@ [ "$status" -eq 0 ] } +@test "checking process: amavis (amavis disabled by DISABLE_AMAVIS)" { + run docker exec mail_disabled_amavis /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/amavisd-new'" + [ "$status" -eq 1 ] +} + +@test "checking process: spamassassin (spamassassin disabled by DISABLE_SPAMASSASSIN)" { + run docker exec mail_disabled_spamassassin /bin/bash -c "ps aux --forest | grep -v grep | grep ''/usr/sbin/spamd'" + [ "$status" -eq 1 ] +} + +@test "checking process: clamav (clamav disabled by DISABLE_CLAMAV)" { + run docker exec mail_disabled_clamav /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" + [ "$status" -eq 1 ] +} + # # imap #