mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
function _defunc removed (#2199)
* function _defunc removed * _shutdown is better than just notify in that cases * PANIC_TYPE 'fail-init' introduced Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
This commit is contained in:
parent
6715e0bba9
commit
c7e9dd2bad
|
@ -21,13 +21,17 @@ function errex
|
|||
# PANIC_SCOPE => Optionally provide a string for debugging to better identify/locate the source of the panic.
|
||||
function dms_panic
|
||||
{
|
||||
local PANIC_TYPE=$1
|
||||
local PANIC_INFO=$2
|
||||
local PANIC_SCOPE=$3 #optional
|
||||
local PANIC_TYPE=${1}
|
||||
local PANIC_INFO=${2}
|
||||
local PANIC_SCOPE=${3} #optional
|
||||
|
||||
local SHUTDOWN_MESSAGE
|
||||
|
||||
case "${PANIC_TYPE}" in
|
||||
( 'fail-init' ) # PANIC_INFO == <name of service or process that failed to start / initialize>
|
||||
SHUTDOWN_MESSAGE="Failed to start ${PANIC_INFO}!"
|
||||
;;
|
||||
|
||||
( 'no-env' ) # PANIC_INFO == <ENV VAR name>
|
||||
SHUTDOWN_MESSAGE="Environment Variable: ${PANIC_INFO} is not set!"
|
||||
;;
|
||||
|
@ -58,6 +62,7 @@ function dms_panic
|
|||
}
|
||||
|
||||
# Convenience wrappers based on type:
|
||||
function dms_panic__fail_init { dms_panic 'fail-init' "${1}" "${2}"; }
|
||||
function dms_panic__no_env { dms_panic 'no-env' "${1}" "${2}"; }
|
||||
function dms_panic__no_file { dms_panic 'no-file' "${1}" "${2}"; }
|
||||
function dms_panic__misconfigured { dms_panic 'misconfigured' "${1}" "${2}"; }
|
||||
|
|
|
@ -217,12 +217,6 @@ function _register_misc_function
|
|||
_notify 'inf' "${1}() registered"
|
||||
}
|
||||
|
||||
function _defunc
|
||||
{
|
||||
_notify 'fatal' 'Please fix your configuration. Exiting...'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# ? << Registering functions
|
||||
# --
|
||||
|
|
|
@ -5,7 +5,7 @@ function check
|
|||
_notify 'tasklog' 'Checking configuration'
|
||||
for FUNC in "${FUNCS_CHECK[@]}"
|
||||
do
|
||||
${FUNC} || _defunc
|
||||
${FUNC}
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,5 @@ function _check_hostname
|
|||
if ! grep -q -E '^(\S+[.]\S+)$' <<< "${HOSTNAME}"
|
||||
then
|
||||
_shutdown 'Setting hostname/domainname is required'
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -5,31 +5,31 @@ function start_daemons
|
|||
_notify 'tasklog' 'Starting daemons & mail server'
|
||||
for FUNC in "${DAEMONS_START[@]}"
|
||||
do
|
||||
${FUNC} || _defunc
|
||||
${FUNC}
|
||||
done
|
||||
}
|
||||
|
||||
function _start_daemons_cron
|
||||
{
|
||||
_notify 'task' 'Starting cron'
|
||||
supervisorctl start cron
|
||||
supervisorctl start cron || dms_panic__fail_init 'cron'
|
||||
}
|
||||
|
||||
function _start_daemons_rsyslog
|
||||
{
|
||||
_notify 'task' 'Starting rsyslog'
|
||||
supervisorctl start rsyslog
|
||||
supervisorctl start rsyslog || dms_panic__fail_init 'rsyslog'
|
||||
}
|
||||
|
||||
function _start_daemons_saslauthd
|
||||
{
|
||||
_notify 'task' 'Starting saslauthd'
|
||||
supervisorctl start "saslauthd_${SASLAUTHD_MECHANISMS}"
|
||||
supervisorctl start "saslauthd_${SASLAUTHD_MECHANISMS}" || dms_panic__fail_init 'saslauthd'
|
||||
}
|
||||
|
||||
function _start_daemons_fail2ban
|
||||
{
|
||||
_notify 'task' 'Starting fail2ban'
|
||||
_notify 'task' 'Starting Fail2ban'
|
||||
touch /var/log/auth.log
|
||||
|
||||
# delete fail2ban.sock that probably was left here after container restart
|
||||
|
@ -38,31 +38,31 @@ function _start_daemons_fail2ban
|
|||
rm /var/run/fail2ban/fail2ban.sock
|
||||
fi
|
||||
|
||||
supervisorctl start fail2ban
|
||||
supervisorctl start fail2ban || dms_panic__fail_init 'Fail2ban'
|
||||
}
|
||||
|
||||
function _start_daemons_opendkim
|
||||
{
|
||||
_notify 'task' 'Starting opendkim'
|
||||
supervisorctl start opendkim
|
||||
supervisorctl start opendkim || dms_panic__fail_init 'opendkim'
|
||||
}
|
||||
|
||||
function _start_daemons_opendmarc
|
||||
{
|
||||
_notify 'task' 'Starting opendmarc'
|
||||
supervisorctl start opendmarc
|
||||
supervisorctl start opendmarc || dms_panic__fail_init 'opendmarc'
|
||||
}
|
||||
|
||||
function _start_daemons_postsrsd
|
||||
{
|
||||
_notify 'task' 'Starting postsrsd'
|
||||
supervisorctl start postsrsd
|
||||
supervisorctl start postsrsd || dms_panic__fail_init 'postsrsd'
|
||||
}
|
||||
|
||||
function _start_daemons_postfix
|
||||
{
|
||||
_notify 'task' 'Starting postfix'
|
||||
supervisorctl start postfix
|
||||
supervisorctl start postfix || dms_panic__fail_init 'postfix'
|
||||
}
|
||||
|
||||
function _start_daemons_dovecot
|
||||
|
@ -81,7 +81,7 @@ function _start_daemons_dovecot
|
|||
cp /tmp/docker-mailserver/dovecot.cf /etc/dovecot/local.conf
|
||||
fi
|
||||
|
||||
supervisorctl start dovecot
|
||||
supervisorctl start dovecot || dms_panic__fail_init 'dovecot'
|
||||
}
|
||||
|
||||
function _start_daemons_fetchmail
|
||||
|
@ -120,41 +120,41 @@ EOF
|
|||
do
|
||||
COUNTER=$(( COUNTER + 1 ))
|
||||
_notify 'task' "Starting fetchmail instance ${COUNTER}"
|
||||
supervisorctl start "fetchmail-${COUNTER}"
|
||||
supervisorctl start "fetchmail-${COUNTER}" || _panic__fail_init "fetchmail-${COUNTER}"
|
||||
done
|
||||
else
|
||||
_notify 'task' 'Starting fetchmail'
|
||||
supervisorctl start fetchmail
|
||||
supervisorctl start fetchmail || dms_panic__fail_init 'fetchmail'
|
||||
fi
|
||||
}
|
||||
|
||||
function _start_daemons_clamav
|
||||
{
|
||||
_notify 'task' 'Starting clamav'
|
||||
supervisorctl start clamav
|
||||
supervisorctl start clamav || dms_panic__fail_init 'ClamAV'
|
||||
}
|
||||
|
||||
function _start_daemons_postgrey
|
||||
{
|
||||
_notify 'task' 'Starting postgrey'
|
||||
rm -f /var/run/postgrey/postgrey.pid
|
||||
supervisorctl start postgrey
|
||||
supervisorctl start postgrey || dms_panic__fail_init 'postgrey'
|
||||
}
|
||||
|
||||
function _start_daemons_amavis
|
||||
{
|
||||
_notify 'task' 'Starting amavis'
|
||||
supervisorctl start amavis
|
||||
supervisorctl start amavis || dms_panic__fail_init 'amavis'
|
||||
}
|
||||
|
||||
function _start_changedetector
|
||||
{
|
||||
_notify 'task' 'Starting changedetector'
|
||||
supervisorctl start changedetector
|
||||
supervisorctl start changedetector || dms_panic__fail_init 'changedetector'
|
||||
}
|
||||
|
||||
function _start_daemons_update_check
|
||||
{
|
||||
_notify 'task' 'Starting update-check'
|
||||
supervisorctl start update-check
|
||||
supervisorctl start update-check || dms_panic__fail_init 'update-check'
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ function fix
|
|||
_notify 'tasklog' 'Post-configuration checks'
|
||||
for FUNC in "${FUNCS_FIX[@]}"
|
||||
do
|
||||
${FUNC} || _defunc
|
||||
${FUNC}
|
||||
done
|
||||
|
||||
_notify 'inf' 'Removing leftover PID files from a stop/start'
|
||||
|
@ -21,12 +21,10 @@ function _fix_var_mail_permissions
|
|||
if find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | read -r
|
||||
then
|
||||
_notify 'inf' 'Fixing /var/mail permissions'
|
||||
chown -R 5000:5000 /var/mail
|
||||
chown -R 5000:5000 /var/mail || _shutdown 'Failed to fix /var/mail permissions'
|
||||
else
|
||||
_notify 'inf' 'Permissions in /var/mail look OK'
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function _fix_var_amavis_permissions
|
||||
|
@ -35,21 +33,18 @@ function _fix_var_amavis_permissions
|
|||
[[ ${ONE_DIR} -eq 0 ]] && AMAVIS_STATE_DIR="/var/lib/amavis"
|
||||
[[ ! -e ${AMAVIS_STATE_DIR} ]] && return 0
|
||||
|
||||
_notify 'inf' 'Checking and fixing Amavis permissions'
|
||||
chown -hR amavis:amavis "${AMAVIS_STATE_DIR}"
|
||||
|
||||
return 0
|
||||
_notify 'inf' 'Fixing Amavis permissions'
|
||||
chown -hR amavis:amavis "${AMAVIS_STATE_DIR}" || _shutdown 'Failed to fix Amavis permissions'
|
||||
}
|
||||
|
||||
function _fix_cleanup_clamav
|
||||
{
|
||||
_notify 'task' 'Cleaning up disabled Clamav'
|
||||
rm -f /etc/logrotate.d/clamav-*
|
||||
rm -f /etc/cron.d/clamav-freshclam
|
||||
_notify 'task' 'Cleaning up disabled ClamAV'
|
||||
rm /etc/logrotate.d/clamav-* /etc/cron.d/clamav-freshclam || _shutdown 'Failed to remove ClamAV configuration'
|
||||
}
|
||||
|
||||
function _fix_cleanup_spamassassin
|
||||
{
|
||||
_notify 'task' 'Cleaning up disabled SpamAssassin'
|
||||
rm -f /etc/cron.daily/spamassassin
|
||||
rm /etc/cron.daily/spamassassin || _shutdown 'Failed to remove SpamAssassin configuration'
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ function start_misc
|
|||
_notify 'inf' 'Starting miscellaneous tasks'
|
||||
for FUNC in "${FUNCS_MISC[@]}"
|
||||
do
|
||||
${FUNC} || _defunc
|
||||
${FUNC}
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
@ -373,8 +373,7 @@ function _setup_dovecot_local_user
|
|||
then
|
||||
if [[ ${ENABLE_LDAP} -eq 0 ]]
|
||||
then
|
||||
_notify 'fatal' 'Unless using LDAP, you need at least 1 email account to start Dovecot.'
|
||||
_defunc
|
||||
_shutdown 'Unless using LDAP, you need at least 1 email account to start Dovecot.'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue