mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
scripts: improve shutdown function by making PANIC_STRATEGY obsolete (#3265)
This commit is contained in:
parent
a735dddc52
commit
ea07bcdb4c
|
@ -144,7 +144,7 @@ function _create_dovecot_alias_dummy_accounts
|
|||
|
||||
if [[ -z ${REAL_ACC[1]} ]]
|
||||
then
|
||||
_dms_panic__misconfigured 'postfix-accounts.cf' 'alias configuration' 'immediate'
|
||||
_dms_panic__misconfigured 'postfix-accounts.cf' 'alias configuration'
|
||||
fi
|
||||
|
||||
# test if user has a defined quota
|
||||
|
|
|
@ -24,8 +24,7 @@ function dms_panic
|
|||
{
|
||||
local PANIC_TYPE=${1:-}
|
||||
local PANIC_INFO=${2:-}
|
||||
local PANIC_SCOPE=${3-} # optional, must not be :- but just -
|
||||
local PANIC_STRATEGY=${4:-} # optional
|
||||
local PANIC_SCOPE=${3:-}
|
||||
|
||||
local SHUTDOWN_MESSAGE
|
||||
|
||||
|
@ -61,9 +60,9 @@ function dms_panic
|
|||
|
||||
if [[ -n ${PANIC_SCOPE:-} ]]
|
||||
then
|
||||
_shutdown "${PANIC_SCOPE} | ${SHUTDOWN_MESSAGE}" "${PANIC_STRATEGY}"
|
||||
_shutdown "${PANIC_SCOPE} | ${SHUTDOWN_MESSAGE}"
|
||||
else
|
||||
_shutdown "${SHUTDOWN_MESSAGE}" "${PANIC_STRATEGY}"
|
||||
_shutdown "${SHUTDOWN_MESSAGE}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -77,22 +76,14 @@ function _dms_panic__general { dms_panic 'general' "${1:-}" "${2:-}"
|
|||
|
||||
# Call this method when you want to panic (i.e. emit an 'ERROR' log, and exit uncleanly).
|
||||
# `dms_panic` methods should be preferred if your failure type is supported.
|
||||
trap "exit 1" SIGUSR1
|
||||
SCRIPT_PID=${$}
|
||||
function _shutdown
|
||||
{
|
||||
_log 'error' "${1:-_shutdown called without message}"
|
||||
_log 'error' 'Shutting down'
|
||||
|
||||
sleep 1
|
||||
kill 1
|
||||
|
||||
if [[ ${2:-wait} == 'immediate' ]]
|
||||
then
|
||||
# In case the user requested an immediate exit, he ensure he is not in a subshell
|
||||
# call and exiting the whole script is safe. This way, we make the shutdown quicker.
|
||||
exit 1
|
||||
else
|
||||
# We can simply wait until Supervisord has terminated all processes; this way,
|
||||
# we do not return from a subshell call and continue as if nothing happened.
|
||||
sleep 1000
|
||||
fi
|
||||
kill -SIGTERM 1 # Trigger graceful DMS shutdown.
|
||||
kill -SIGUSR1 "${SCRIPT_PID}" # Stop start-mailserver.sh execution, even when _shutdown() is called from a subshell.
|
||||
}
|
||||
|
|
|
@ -92,13 +92,13 @@ function _replace_by_env_in_file
|
|||
{
|
||||
if [[ -z ${1+set} ]]
|
||||
then
|
||||
_dms_panic__invalid_value 'first argument unset' 'utils.sh:_replace_by_env_in_file' 'immediate'
|
||||
_dms_panic__invalid_value 'first argument unset' 'utils.sh:_replace_by_env_in_file'
|
||||
elif [[ -z ${2+set} ]]
|
||||
then
|
||||
_dms_panic__invalid_value 'second argument unset' 'utils.sh:_replace_by_env_in_file' 'immediate'
|
||||
_dms_panic__invalid_value 'second argument unset' 'utils.sh:_replace_by_env_in_file'
|
||||
elif [[ ! -f ${2} ]]
|
||||
then
|
||||
_dms_panic__invalid_value "file '${2}' does not exist" 'utils.sh:_replace_by_env_in_file' 'immediate'
|
||||
_dms_panic__invalid_value "file '${2}' does not exist" 'utils.sh:_replace_by_env_in_file'
|
||||
fi
|
||||
|
||||
local ENV_PREFIX=${1} CONFIG_FILE=${2}
|
||||
|
|
|
@ -61,11 +61,11 @@ function _register_functions
|
|||
;;
|
||||
|
||||
( 'OIDC' )
|
||||
_dms_panic__fail_init 'OIDC user account provisioning - it is not yet implemented' '' 'immediate'
|
||||
_dms_panic__fail_init 'OIDC user account provisioning - it is not yet implemented'
|
||||
;;
|
||||
|
||||
( * )
|
||||
_dms_panic__invalid_value "'${ACCOUNT_PROVISIONER}' is not a valid value for ACCOUNT_PROVISIONER" '' 'immediate'
|
||||
_dms_panic__invalid_value "'${ACCOUNT_PROVISIONER}' is not a valid value for ACCOUNT_PROVISIONER"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ function _check_hostname
|
|||
# HOSTNAME should be an FQDN (eg: hostname.domain)
|
||||
if ! grep -q -E '^(\S+[.]\S+)$' <<< "${HOSTNAME}"
|
||||
then
|
||||
_dms_panic__general 'Setting hostname/domainname is required' '' 'immediate'
|
||||
_dms_panic__general 'Setting hostname/domainname is required'
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ function _default_start_daemon
|
|||
if [[ ${?} -ne 0 ]]
|
||||
then
|
||||
_log 'error' "${RESULT}"
|
||||
_dms_panic__fail_init "${1}" '' 'immediate'
|
||||
_dms_panic__fail_init "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ function _setup_apply_fixes_after_configuration
|
|||
_log 'debug' 'Checking /var/mail permissions'
|
||||
if ! _chown_var_mail_if_necessary
|
||||
then
|
||||
_dms_panic__general 'Failed to fix /var/mail permissions' '' 'immediate'
|
||||
_dms_panic__general 'Failed to fix /var/mail permissions'
|
||||
fi
|
||||
|
||||
_log 'debug' 'Removing files and directories from older versions'
|
||||
|
|
|
@ -175,7 +175,7 @@ function _setup_dovecot_local_user
|
|||
fi
|
||||
done
|
||||
|
||||
_dms_panic__fail_init 'accounts provisioning because no accounts were provided - Dovecot could not be started' '' 'immediate'
|
||||
_dms_panic__fail_init 'accounts provisioning because no accounts were provided - Dovecot could not be started'
|
||||
}
|
||||
|
||||
__wait_until_an_account_is_added_or_shutdown
|
||||
|
@ -199,7 +199,7 @@ function _setup_dovecot_inet_protocols
|
|||
PROTOCOL='[::]' # IPv6 only
|
||||
else
|
||||
# Unknown value, panic.
|
||||
_dms_panic__invalid_value 'DOVECOT_INET_PROTOCOLS' "${DOVECOT_INET_PROTOCOLS}" 'immediate'
|
||||
_dms_panic__invalid_value 'DOVECOT_INET_PROTOCOLS' "${DOVECOT_INET_PROTOCOLS}"
|
||||
fi
|
||||
|
||||
sedfile -i "s|^#listen =.*|listen = ${PROTOCOL}|g" /etc/dovecot/dovecot.conf
|
||||
|
|
|
@ -22,7 +22,7 @@ function _setup_docker_permit
|
|||
if [[ -z ${CONTAINER_IP} ]]
|
||||
then
|
||||
_log 'error' 'Detecting the container IP address failed'
|
||||
_dms_panic__misconfigured 'NETWORK_INTERFACE' 'Network Setup [docker_permit]' 'immediate'
|
||||
_dms_panic__misconfigured 'NETWORK_INTERFACE' 'Network Setup [docker_permit]'
|
||||
fi
|
||||
|
||||
while read -r IP
|
||||
|
|
Loading…
Reference in a new issue