From 0949f163445c7cd0304b12720d51ff605c4dac03 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> Date: Wed, 1 Mar 2023 16:24:59 +0100 Subject: [PATCH] scripts/ENV: make disabling Redis possible (#3132) * make disabling Redis possible * add documentation * Apply suggestions from code review * Update docs/content/config/environment.md --------- Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com> --- docs/content/config/environment.md | 20 +++++++++++++++++++ mailserver.env | 10 ++++++++-- target/rspamd/local.d/redis.conf | 4 ---- target/scripts/start-mailserver.sh | 13 ++++-------- .../startup/setup.d/security/rspamd.sh | 14 +++++++++++++ target/scripts/startup/variables-stack.sh | 1 + 6 files changed, 47 insertions(+), 15 deletions(-) delete mode 100644 target/rspamd/local.d/redis.conf diff --git a/docs/content/config/environment.md b/docs/content/config/environment.md index 2c619621..269e6f8a 100644 --- a/docs/content/config/environment.md +++ b/docs/content/config/environment.md @@ -80,6 +80,26 @@ Enable or disable Rspamd. - **0** => disabled - 1 => enabled +##### ENABLE_REDIS + +Explicit control over running a Redis instance within the container. By default, this value will match what is set for [`ENABLE_RSPAMD`](#enable_rspamd). + +The purpose of this setting is to opt-out of starting an internal Redis instance when enabling Rspamd, replacing it with your own external instance. + +??? note "Configuring rspamd for an external Redis instance" + + You will need to [provide configuration][config-rspamd-redis] at `/etc/rspamd/local.d/redis.conf` similar to: + + ``` + servers = "redis.example.test:6379"; + expand_keys = true; + ``` + +[config-rspamd-redis]: https://rspamd.com/doc/configuration/redis.html + +- 0 => Disabled +- 1 => Enabled + ##### ENABLE_AMAVIS Amavis content filter (used for ClamAV & SpamAssassin) diff --git a/mailserver.env b/mailserver.env index fdb6caa2..15481222 100644 --- a/mailserver.env +++ b/mailserver.env @@ -118,10 +118,16 @@ ENABLE_POP3= ENABLE_CLAMAV=0 # Enables Rspamd -# **0** => disabled -# 1 => enabled +# **0** => Disabled +# 1 => Enabled ENABLE_RSPAMD=0 +# When `ENABLE_RSPAMD=1`, an internal Redis instance is enabled implicitly. +# This setting provides an opt-out to allow using an external instance instead. +# 0 => Disabled +# 1 => Enabled +ENABLE_REDIS= + # Amavis content filter (used for ClamAV & SpamAssassin) # 0 => Disabled # 1 => Enabled diff --git a/target/rspamd/local.d/redis.conf b/target/rspamd/local.d/redis.conf deleted file mode 100644 index 81658d5e..00000000 --- a/target/rspamd/local.d/redis.conf +++ /dev/null @@ -1,4 +0,0 @@ -# documentation: https://rspamd.com/doc/configuration/redis.html - -servers = "127.0.0.1:6379"; -expand_keys = true; diff --git a/target/scripts/start-mailserver.sh b/target/scripts/start-mailserver.sh index 6ba91cad..2cf87b11 100755 --- a/target/scripts/start-mailserver.sh +++ b/target/scripts/start-mailserver.sh @@ -123,16 +123,11 @@ function _register_functions _register_start_daemon '_start_daemon_cron' _register_start_daemon '_start_daemon_rsyslog' - [[ ${SMTP_ONLY} -ne 1 ]] && _register_start_daemon '_start_daemon_dovecot' - [[ ${ENABLE_UPDATE_CHECK} -eq 1 ]] && _register_start_daemon '_start_daemon_update_check' - - if [[ ${ENABLE_RSPAMD} -eq 1 ]] - then - _register_start_daemon '_start_daemon_redis' - _register_start_daemon '_start_daemon_rspamd' - fi - [[ ${SMTP_ONLY} -ne 1 ]] && _register_start_daemon '_start_daemon_dovecot' + + [[ ${ENABLE_UPDATE_CHECK} -eq 1 ]] && _register_start_daemon '_start_daemon_update_check' + [[ ${ENABLE_REDIS} -eq 1 ]] && _register_start_daemon '_start_daemon_rspamd' + [[ ${ENABLE_RSPAMD} -eq 1 ]] && _register_start_daemon '_start_daemon_redis' [[ ${ENABLE_UPDATE_CHECK} -eq 1 ]] && _register_start_daemon '_start_daemon_update_check' # needs to be started before SASLauthd diff --git a/target/scripts/startup/setup.d/security/rspamd.sh b/target/scripts/startup/setup.d/security/rspamd.sh index a3d8237f..f9ebab32 100644 --- a/target/scripts/startup/setup.d/security/rspamd.sh +++ b/target/scripts/startup/setup.d/security/rspamd.sh @@ -46,6 +46,20 @@ function __rspamd__preflight_checks else __rspamd__log 'debug' 'Rspamd will not use ClamAV (which has not been enabled)' fi + + if [[ ${ENABLE_REDIS} -eq 1 ]] + then + __rspamd__log 'trace' 'Internal Redis is enabled, adding configuration' + cat >/etc/rspamd/local.d/redis.conf << "EOF" +# documentation: https://rspamd.com/doc/configuration/redis.html + +servers = "127.0.0.1:6379"; +expand_keys = true; + +EOF + else + __rspamd__log 'debug' 'Rspamd will not use internal Redis (which has been disabled)' + fi } # Adjust Postfix's configuration files. Append Rspamd at the end of diff --git a/target/scripts/startup/variables-stack.sh b/target/scripts/startup/variables-stack.sh index bb0a197f..66e98a5a 100644 --- a/target/scripts/startup/variables-stack.sh +++ b/target/scripts/startup/variables-stack.sh @@ -77,6 +77,7 @@ function __environment_variables_general_setup VARS[ENABLE_POSTGREY]="${ENABLE_POSTGREY:=0}" VARS[ENABLE_QUOTAS]="${ENABLE_QUOTAS:=1}" VARS[ENABLE_RSPAMD]="${ENABLE_RSPAMD:=0}" + VARS[ENABLE_REDIS]="${ENABLE_REDIS:=${ENABLE_RSPAMD}}" VARS[ENABLE_SASLAUTHD]="${ENABLE_SASLAUTHD:=0}" VARS[ENABLE_SPAMASSASSIN]="${ENABLE_SPAMASSASSIN:=0}" VARS[ENABLE_SPAMASSASSIN_KAM]="${ENABLE_SPAMASSASSIN_KAM:=0}"