Commit b3aefbbc authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Fix helper's error monitoring system

Fix a bug where errors that where not created using log_error where
not registered to the monitoring subsystem.
parent 4989b80b
......@@ -70,8 +70,10 @@ report_error() {
log_error() {
ERRORS+=("$*")
echo "ERROR: $@" | tee $RESULT >&2
report_error
exit 1
# Use return instead of exit. The set -x options will terminate the script
# but will also trigger ERR traps if defined.
return 1
}
warn() {
......@@ -404,6 +406,8 @@ task_cleanup() {
if [ $rc -eq 0 ]; then
report_task_end
else
report_error
fi
cleanup
......
......@@ -33,6 +33,11 @@ fi
set -e
# Enable errtrace to make functions inherit the ERR trap
set -o errtrace
trap report_error ERR
if grep snf_image_activate_helper /proc/cmdline > /dev/null; then
# terminate helper vm when the script exits
add_cleanup system_poweroff
......@@ -88,9 +93,6 @@ if [ -z "$RUN_PARTS" ]; then
log_error "run-parts program is missing from the system"
fi
# If something goes wrong with the tasks, try to umount the target filesystem
# in case it is left mounted...
trap '{ umount "$target"; }' ERR
if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
......@@ -108,6 +110,10 @@ if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
log_error "Supported values for OSFAMILY property are: linux|windows"
fi
# If something goes wrong with the tasks, try to umount the target
# file system in case it is left mounted...
trap '{ umount "$target"; }' ERR
# Redirect standard error to standard output,
# prepend a timestamp before each line of output.
echo "Execute all snf-image tasks...."
......@@ -115,10 +121,10 @@ if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
while IFS= read -r line; do
echo $($DATE +%Y:%m:%d-%H:%M:%S.%N) "$line"
done
trap report_error ERR
fi
# Disable the trap. If code reaches here, the filesystem is unmounted.
trap - ERR
echo "SUCCESS" > "$RESULT"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment