From bd1ee52278ae7ac194482b8ec5c1b2d4252becc6 Mon Sep 17 00:00:00 2001 From: belliash Date: Fri, 30 Dec 2011 21:37:46 +0100 Subject: [PATCH] implement die() --- libraries/common | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/common b/libraries/common index e7eb082..d2f8919 100644 --- a/libraries/common +++ b/libraries/common @@ -3,6 +3,21 @@ # Distributed under the terms of the GNU General Public License v3 +#------------------------------------------------------------------------------- +# Outputs formatted error message and aborts script execution with given code +# Parameters: %message% %code% +#------------------------------------------------------------------------------- +function die() { + if isEnabled ${LOGGING} && isSet NOTIFY; then + local LOGS="Full output from logs:\n\n$(cat ${LOGFILE})" + local MESG="The ${EZNAME} has failed with code: ${2} and message: ${1}" + local TOPIC="The ${EZNAME} process has failed!" + echo -e "${MESG}\n${LOGS}" | mailx -s "${TOPIC}" "${NOTIFY}" + fi + printError "${1}" + exit ${2} +} + #------------------------------------------------------------------------------- # Checks whether a supplied variable is defined or not # Parameters: %variable%