Skip to content

Commit

Permalink
Better support regular container restarts (docker-mailserver#3929)
Browse files Browse the repository at this point in the history
Co-authored-by: Brennan Kinney <[email protected]>
Co-authored-by: Georg Lauterbach <[email protected]>
  • Loading branch information
3 people authored Mar 17, 2024
1 parent 910667d commit 066773e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ The most noteworthy change of this release is the update of the container's base
- `LOGROTATE_COUNT` defines the number of files kept by logrotate ([#3907](https://github.com/docker-mailserver/docker-mailserver/pull/3907))
- The fail2ban log file is now also taken into account by `LOGROTATE_COUNT` and `LOGROTATE_INTERVAL` ([#3915](https://github.com/docker-mailserver/docker-mailserver/pull/3915), [#3919](https://github.com/docker-mailserver/docker-mailserver/pull/3919))

- **Internal:**
- Regular container restarts are now better supported. Setup scripts that ran previously will now be skipped ([#3929](https://github.com/docker-mailserver/docker-mailserver/pull/3929))

### Updates

- **Environment Variables:**
Expand Down
36 changes: 23 additions & 13 deletions target/scripts/start-mailserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function _register_functions() {

# ? >> Checks

_register_check_function '_check_improper_restart'
_register_check_function '_check_hostname'
_register_check_function '_check_log_level'
_register_check_function '_check_spam_prefix'
Expand Down Expand Up @@ -170,24 +169,35 @@ function _register_functions() {
# ? >> Executing all stacks / actual start of DMS
# ------------------------------------------------------------

_early_supervisor_setup
_early_variables_setup
# Ensure DMS only adjusts config files for a new container.
# Container restarts should skip as they retain the modified config.
if [[ ! -f /CONTAINER_START ]]; then
_early_supervisor_setup
_early_variables_setup

_log 'info' "Welcome to docker-mailserver ${DMS_RELEASE}"
_log 'info' "Welcome to docker-mailserver ${DMS_RELEASE}"

_register_functions
_check
_setup
[[ ${LOG_LEVEL} =~ (debug|trace) ]] && print-environment
_run_user_patches
_start_daemons
_register_functions
_check
_setup
_run_user_patches
else
# container was restarted
_early_variables_setup

_log 'info' 'Container was restarted. Skipping setup routines.'
_log 'info' "Welcome to docker-mailserver ${DMS_RELEASE}"

_register_functions
fi

# marker to check if container was restarted
date >/CONTAINER_START

[[ ${LOG_LEVEL} =~ (debug|trace) ]] && print-environment
_start_daemons

_log 'info' "${HOSTNAME} is up and running"

touch /var/log/mail/mail.log
tail -Fn 0 /var/log/mail/mail.log

exit 0
exec tail -Fn 0 /var/log/mail/mail.log
9 changes: 0 additions & 9 deletions target/scripts/startup/check-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ function _check() {
done
}

function _check_improper_restart() {
_log 'debug' 'Checking for improper restart'

if [[ -f /CONTAINER_START ]]; then
_log 'warn' 'This container was (likely) improperly restarted which can result in undefined behavior'
_log 'warn' "Please use 'docker compose up --force-recreate' or equivalent (view our troubleshooting docs)"
fi
}

function _check_hostname() {
_log 'debug' 'Checking that hostname/domainname is provided or overridden'

Expand Down
2 changes: 1 addition & 1 deletion target/scripts/startup/setup-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function _early_supervisor_setup() {
if ! grep -q "loglevel = ${SUPERVISOR_LOGLEVEL}" /etc/supervisor/supervisord.conf; then
case "${SUPERVISOR_LOGLEVEL}" in
( 'critical' | 'error' | 'info' | 'debug' )
sed -i -E \
sedfile -i -E \
"s|(loglevel).*|\1 = ${SUPERVISOR_LOGLEVEL}|g" \
/etc/supervisor/supervisord.conf

Expand Down

0 comments on commit 066773e

Please sign in to comment.