From 26053c22bd9c8b41735d6628caa6810316f27bc1 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Mon, 22 Aug 2022 10:44:23 +1200 Subject: [PATCH] fix: `_create_accounts()` should run after waiting (#2731) When waiting on an account to be added to `postfix-accounts.cf`, Dovecot account creation during the startup process had already run. Startup continued without properly creating the mail account for Dovecot. Methods like `setup email list` (with `ENABLE_QUOTAS=1`) would fail. `changedetector` service was required to be triggered to re-create Dovecot users. - Wrapped the logic for wait + shutdown into a function call. - Moved `_create_accounts()` to bottom of the setup function. --- target/scripts/startup/setup-stack.sh | 35 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/target/scripts/startup/setup-stack.sh b/target/scripts/startup/setup-stack.sh index 92eb43f3..03abbe1d 100644 --- a/target/scripts/startup/setup-stack.sh +++ b/target/scripts/startup/setup-stack.sh @@ -276,27 +276,34 @@ function _setup_dovecot_local_user { _log 'debug' 'Setting up Dovecot Local User' - _create_accounts [[ ${ENABLE_LDAP} -eq 1 ]] && return 0 if [[ ! -f /tmp/docker-mailserver/postfix-accounts.cf ]] then - _log 'trace' "'/tmp/docker-mailserver/postfix-accounts.cf' not provided, no mail account created" + _log 'trace' "No mail accounts to create - '/tmp/docker-mailserver/postfix-accounts.cf' is missing" fi - local SLEEP_PERIOD='10' - for (( COUNTER = 11 ; COUNTER >= 0 ; COUNTER-- )) - do - if [[ $(grep -cE '.+@.+\|' /tmp/docker-mailserver/postfix-accounts.cf 2>/dev/null || printf '%s' '0') -ge 1 ]] - then - return 0 - else - _log 'warn' "You need at least one email account to start Dovecot ($(( ( COUNTER + 1 ) * SLEEP_PERIOD ))s left for account creation before shutdown)" - sleep "${SLEEP_PERIOD}" - fi - done + function __wait_until_an_account_is_added_or_shutdown + { + local SLEEP_PERIOD='10' - _shutdown 'No accounts provided - Dovecot could not be started' + for (( COUNTER = 11 ; COUNTER >= 0 ; COUNTER-- )) + do + if [[ $(grep -cE '.+@.+\|' /tmp/docker-mailserver/postfix-accounts.cf 2>/dev/null || printf '%s' '0') -ge 1 ]] + then + return 0 + else + _log 'warn' "You need at least one mail account to start Dovecot ($(( ( COUNTER + 1 ) * SLEEP_PERIOD ))s left for account creation before shutdown)" + sleep "${SLEEP_PERIOD}" + fi + done + + _shutdown 'No accounts provided - Dovecot could not be started' + } + + __wait_until_an_account_is_added_or_shutdown + + _create_accounts } function _setup_ldap