Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: housekeeping & cleanup setup (2/2) #3123

Merged
merged 8 commits into from
Feb 28, 2023
2 changes: 1 addition & 1 deletion target/bin/debug-fetchmail
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source /usr/local/bin/helpers/log.sh
# shellcheck source=../scripts/startup/setup.d/fetchmail.sh
source /usr/local/bin/setup.d/fetchmail.sh

_setup_fetchmail
ENABLE_FETCHMAIL=1 _setup_fetchmail

su -s /bin/sh -c "/usr/bin/fetchmail \
--verbose \
Expand Down
30 changes: 9 additions & 21 deletions target/scripts/start-mailserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ source /usr/local/bin/daemons-stack.sh
# ------------------------------------------------------------
# ? << Sourcing helpers & stacks
# --
# ? >> Early setup & environment variables setup
# ------------------------------------------------------------

_early_setup_supervisor
_early_variables_setup

# ------------------------------------------------------------
# ? << Early setup & environment variables setup
# --
# ? >> Registering functions
# ------------------------------------------------------------

Expand Down Expand Up @@ -82,8 +73,8 @@ function _register_functions
_register_setup_function '_setup_saslauthd'
fi

[[ ${POSTFIX_INET_PROTOCOLS} != 'all' ]] && _register_setup_function '_setup_postfix_inet_protocols'
[[ ${DOVECOT_INET_PROTOCOLS} != 'all' ]] && _register_setup_function '_setup_dovecot_inet_protocols'
_register_setup_function '_setup_postfix_inet_protocols'
_register_setup_function '_setup_dovecot_inet_protocols'

_register_setup_function '_setup_opendkim'
_register_setup_function '_setup_opendmarc' # must come after `_setup_opendkim`
Expand All @@ -103,14 +94,10 @@ function _register_functions
_register_setup_function '_setup_postfix_vhost'
_register_setup_function '_setup_postfix_dhparam'
_register_setup_function '_setup_postfix_sizelimits'
_register_setup_function '_setup_fetchmail'
_register_setup_function '_setup_fetchmail_parallel'

# needs to come after _setup_postfix_aliases

if [[ ${ENABLE_FETCHMAIL} -eq 1 ]]
then
_register_setup_function '_setup_fetchmail'
[[ ${FETCHMAIL_PARALLEL} -eq 1 ]] && _register_setup_function '_setup_fetchmail_parallel'
fi
_register_setup_function '_setup_spoof_protection'

if [[ ${ENABLE_SRS} -eq 1 ]]
Expand All @@ -121,9 +108,7 @@ function _register_functions

_register_setup_function '_setup_postfix_access_control'
_register_setup_function '_setup_postfix_relay_hosts'

[[ -n ${POSTFIX_DAGENT} ]] && _register_setup_function '_setup_postfix_virtual_transport'

_register_setup_function '_setup_postfix_virtual_transport'
_register_setup_function '_setup_postfix_override_configuration'
_register_setup_function '_setup_logrotate'
_register_setup_function '_setup_mail_summary'
Expand Down Expand Up @@ -174,13 +159,16 @@ function _register_functions
# ? >> Executing all stacks / actual start of DMS
# ------------------------------------------------------------

_early_supervisor_setup
_early_variables_setup

_log 'info' "Welcome to docker-mailserver $(</VERSION)"

_register_functions
_check
_setup
[[ ${LOG_LEVEL} =~ (debug|trace) ]] && print-environment
_setup_run_user_patches
_run_user_patches
_start_daemons

# marker to check if container was restarted
Expand Down
35 changes: 7 additions & 28 deletions target/scripts/startup/daemons-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ function _default_start_daemon
# shellcheck disable=SC2181
if [[ ${?} -ne 0 ]]
then
echo "${RESULT}" >&2
_log 'error' "${RESULT}"
dms_panic__fail_init "${1}"
fi
}

function _start_daemon_changedetector { _default_start_daemon 'changedetector' ; }
function _start_daemon_amavis { _default_start_daemon 'amavis' ; }
function _start_daemon_changedetector { _default_start_daemon 'changedetector' ; }
function _start_daemon_clamav { _default_start_daemon 'clamav' ; }
function _start_daemon_cron { _default_start_daemon 'cron' ; }
function _start_daemon_dovecot { _default_start_daemon 'dovecot' ; }
function _start_daemon_fail2ban { _default_start_daemon 'fail2ban' ; }
function _start_daemon_opendkim { _default_start_daemon 'opendkim' ; }
function _start_daemon_opendmarc { _default_start_daemon 'opendmarc' ; }
function _start_daemon_postgrey { _default_start_daemon 'postgrey' ; }
function _start_daemon_postsrsd { _default_start_daemon 'postsrsd' ; }
function _start_daemon_redis { _default_start_daemon 'redis' ; }
function _start_daemon_rspamd { _default_start_daemon 'rspamd' ; }
function _start_daemon_rsyslog { _default_start_daemon 'rsyslog' ; }
function _start_daemon_update_check { _default_start_daemon 'update-check' ; }
function _start_daemon_rspamd { _default_start_daemon 'rspamd' ; }
function _start_daemon_redis { _default_start_daemon 'redis' ; }

function _start_daemon_saslauthd
{
Expand All @@ -56,30 +59,6 @@ function _start_daemon_postfix
_default_start_daemon 'postfix'
}

function _start_daemon_postgrey
{
rm -f /var/run/postgrey/postgrey.pid
_default_start_daemon 'postgrey'
}

function _start_daemon_fail2ban
{
_default_start_daemon 'fail2ban'
}

function _start_daemon_dovecot
{
if [[ ${ENABLE_POP3} -eq 1 ]]
then
_log 'debug' 'Enabling POP3 services'
mv /etc/dovecot/protocols.d/pop3d.protocol.disab /etc/dovecot/protocols.d/pop3d.protocol
fi

[[ -f /tmp/docker-mailserver/dovecot.cf ]] && cp /tmp/docker-mailserver/dovecot.cf /etc/dovecot/local.conf

_default_start_daemon 'dovecot'
}

function _start_daemon_fetchmail
{
if [[ ${FETCHMAIL_PARALLEL} -eq 1 ]]
Expand Down
30 changes: 16 additions & 14 deletions target/scripts/startup/setup-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function _setup
_prepare_for_change_detection
}

function _early_setup_supervisor
function _early_supervisor_setup
{
SUPERVISOR_LOGLEVEL="${SUPERVISOR_LOGLEVEL:-warn}"

Expand Down Expand Up @@ -78,19 +78,6 @@ function _setup_file_permissions
chmod 640 /var/log/mail/freshclam.log
}

function _setup_run_user_patches
{
local USER_PATCHES='/tmp/docker-mailserver/user-patches.sh'

if [[ -f ${USER_PATCHES} ]]
then
_log 'debug' 'Applying user patches'
/bin/bash "${USER_PATCHES}"
else
_log 'trace' "No optional '${USER_PATCHES}' provided"
fi
}

function _setup_timezone
{
[[ -n ${TZ} ]] || return 0
Expand All @@ -113,11 +100,26 @@ function _setup_timezone
return 1
fi
}

function _setup_apply_fixes_after_configuration
{
_log 'trace' 'Removing leftover PID files from a stop/start'
find /var/run/ -not -name 'supervisord.pid' -name '*.pid' -delete
touch /dev/shm/supervisor.sock

_log 'debug' 'Checking /var/mail permissions'
_chown_var_mail_if_necessary || _shutdown 'Failed to fix /var/mail permissions'
}

function _run_user_patches
{
local USER_PATCHES='/tmp/docker-mailserver/user-patches.sh'

if [[ -f ${USER_PATCHES} ]]
then
_log 'debug' 'Applying user patches'
/bin/bash "${USER_PATCHES}"
else
_log 'trace' "No optional '${USER_PATCHES}' provided"
fi
}
11 changes: 10 additions & 1 deletion target/scripts/startup/setup.d/dovecot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ function _setup_dovecot
chown docker:docker -R /usr/lib/dovecot/sieve*
chmod 550 -R /usr/lib/dovecot/sieve*
chmod -f +x /usr/lib/dovecot/sieve-pipe/*

if [[ ${ENABLE_POP3} -eq 1 ]]
then
_log 'debug' 'Enabling POP3 services'
mv /etc/dovecot/protocols.d/pop3d.protocol.disab /etc/dovecot/protocols.d/pop3d.protocol
fi

[[ -f /tmp/docker-mailserver/dovecot.cf ]] && cp /tmp/docker-mailserver/dovecot.cf /etc/dovecot/local.conf
}


Expand Down Expand Up @@ -184,10 +192,11 @@ function _setup_dovecot_local_user

function _setup_dovecot_inet_protocols
{
local PROTOCOL
[[ ${DOVECOT_INET_PROTOCOLS} == 'all' ]] && return 0

_log 'trace' 'Setting up DOVECOT_INET_PROTOCOLS option'

local PROTOCOL
# https://dovecot.org/doc/dovecot-example.conf
if [[ ${DOVECOT_INET_PROTOCOLS} == "ipv4" ]]
then
Expand Down