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.
This commit is contained in:
Brennan Kinney 2022-08-22 10:44:23 +12:00 committed by GitHub
parent 0b8b77ad88
commit 26053c22bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -276,27 +276,34 @@ function _setup_dovecot_local_user
{ {
_log 'debug' 'Setting up Dovecot Local User' _log 'debug' 'Setting up Dovecot Local User'
_create_accounts
[[ ${ENABLE_LDAP} -eq 1 ]] && return 0 [[ ${ENABLE_LDAP} -eq 1 ]] && return 0
if [[ ! -f /tmp/docker-mailserver/postfix-accounts.cf ]] if [[ ! -f /tmp/docker-mailserver/postfix-accounts.cf ]]
then 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 fi
function __wait_until_an_account_is_added_or_shutdown
{
local SLEEP_PERIOD='10' local SLEEP_PERIOD='10'
for (( COUNTER = 11 ; COUNTER >= 0 ; COUNTER-- )) for (( COUNTER = 11 ; COUNTER >= 0 ; COUNTER-- ))
do do
if [[ $(grep -cE '.+@.+\|' /tmp/docker-mailserver/postfix-accounts.cf 2>/dev/null || printf '%s' '0') -ge 1 ]] if [[ $(grep -cE '.+@.+\|' /tmp/docker-mailserver/postfix-accounts.cf 2>/dev/null || printf '%s' '0') -ge 1 ]]
then then
return 0 return 0
else else
_log 'warn' "You need at least one email account to start Dovecot ($(( ( COUNTER + 1 ) * SLEEP_PERIOD ))s left for account creation before shutdown)" _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}" sleep "${SLEEP_PERIOD}"
fi fi
done done
_shutdown 'No accounts provided - Dovecot could not be started' _shutdown 'No accounts provided - Dovecot could not be started'
}
__wait_until_an_account_is_added_or_shutdown
_create_accounts
} }
function _setup_ldap function _setup_ldap