mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-06-27 03:09:26 +02:00
scripts: apply fixes to helpers when using set -eE
(#3285)
For an upcoming PR, these changes are required, because the script that is using the helpers uses `set -eE`. This leads to situations where errors are not properly handled in our helpers (yet; I plan on changing that in the future).
This commit is contained in:
parent
449d53fc3f
commit
7e7497ae5a
4 changed files with 36 additions and 4 deletions
|
@ -87,3 +87,26 @@ function _shutdown
|
|||
kill -SIGTERM 1 # Trigger graceful DMS shutdown.
|
||||
kill -SIGUSR1 "${SCRIPT_PID}" # Stop start-mailserver.sh execution, even when _shutdown() is called from a subshell.
|
||||
}
|
||||
|
||||
# Calling this function sets up a handler for the `ERR` signal, that occurs when
|
||||
# an error is not properly checked (e.g., in an `if`-clause or in an `&&` block).
|
||||
#
|
||||
# This is mostly useful for debugging. It also helps when using something like `set -eE`,
|
||||
# as it shows where the script aborts.
|
||||
function _trap_err_signal
|
||||
{
|
||||
trap '__log_unexpected_error "${FUNCNAME[0]:-}" "${BASH_COMMAND:-}" "${LINENO:-}" "${?:-}"' ERR
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function __log_unexpected_error
|
||||
{
|
||||
local MESSAGE="Unexpected error occured :: script = ${SCRIPT:-${0}} "
|
||||
MESSAGE+=" | function = ${1:-none (global)}"
|
||||
MESSAGE+=" | command = ${2:-?}"
|
||||
MESSAGE+=" | line = ${3:-?}"
|
||||
MESSAGE+=" | exit code = ${4:-?}"
|
||||
|
||||
_log 'error' "${MESSAGE}"
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue