Browse Source
Merge pull request #195 from oleorhagen/cleanerlog
Report which error occured before exiting
2.1.x
oleorhagen
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
30 additions and
7 deletions
-
mender-convert
-
mender-convert-extract
-
modules/log.sh
-
modules/run.sh
|
|
@ -44,6 +44,12 @@ function show_version() { |
|
|
|
} |
|
|
|
|
|
|
|
function trap_exit() { |
|
|
|
EXIT_CODE=$? |
|
|
|
if [[ ${EXIT_CODE} -ne 0 && ${EXIT_CODE} -ne ${FATAL_EXIT_CODE} ]]; then |
|
|
|
log_error "mender-convert failed" |
|
|
|
tac work/convert.log | sed '/DEBUG/q' | tac | sed 's/Running/When running/' |
|
|
|
log_error "mender-convert exit code: ${EXIT_CODE}" |
|
|
|
fi |
|
|
|
sudo rm -rf work |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -14,6 +14,17 @@ |
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
# limitations under the License. |
|
|
|
|
|
|
|
function trap_exit() { |
|
|
|
echo "mender-convert-extract has finished. Cleaning up..." |
|
|
|
} |
|
|
|
|
|
|
|
function trap_term() { |
|
|
|
true |
|
|
|
} |
|
|
|
|
|
|
|
trap trap_term INT TERM |
|
|
|
trap trap_exit EXIT |
|
|
|
|
|
|
|
echo "Running $(basename $0): $@" |
|
|
|
|
|
|
|
source modules/bootstrap.sh |
|
|
|
|
|
@ -68,8 +68,9 @@ function log_error { |
|
|
|
} |
|
|
|
|
|
|
|
# Log the given message at FATAL level. |
|
|
|
FATAL_EXIT_CODE=90 |
|
|
|
function log_fatal { |
|
|
|
local -r message="$1" |
|
|
|
log "${IRED}FATAL${NC}" "$message" |
|
|
|
exit 1 |
|
|
|
exit ${FATAL_EXIT_CODE} |
|
|
|
} |
|
|
|
|
|
@ -19,10 +19,15 @@ |
|
|
|
# $1 - command to run |
|
|
|
function run_and_log_cmd() { |
|
|
|
local -r cmd="${1}" |
|
|
|
|
|
|
|
log_debug "Running: \n\r\n\r\t ${cmd}" |
|
|
|
log_debug "Run result: \n\r" |
|
|
|
|
|
|
|
result=$(eval ${cmd}) |
|
|
|
log_debug "${result}" |
|
|
|
local -r position="(${BASH_SOURCE[1]}:${BASH_LINENO[0]}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }" |
|
|
|
local exit_code=0 |
|
|
|
output="$({ eval ${cmd}; } 2>&1)" || exit_code=$? |
|
|
|
local log_msg="Running: ${position} \n\r\n\r\t${cmd}" |
|
|
|
if [[ "${output}" != "" ]]; then |
|
|
|
log_msg="${log_msg}\n\t${output}\n" |
|
|
|
fi |
|
|
|
log_debug "${log_msg}" |
|
|
|
if [[ ${exit_code} -ne 0 ]]; then |
|
|
|
exit ${exit_code} |
|
|
|
fi |
|
|
|
} |
|
|
|