Skip to content

Commit

Permalink
hostapp-update-hooks: add debug mode
Browse files Browse the repository at this point in the history
This provides an easy switch to enable tracing on HUP hooks that works
both on old and new OS hooks as enabling it depends on a config.json
setting.

It is meant to debug field issues with HUP failure where all we see is:
```
Before hooks (old os) ran successfully
Failed to run the new hooks. Running current hooks..
```
For example:
https://jel.ly.fish/support-thread-1-0-0-front-cnv-eq6ipvx

Change-type: patch
Signed-off-by: Alex Gonzalez <alexg@balena.io>
  • Loading branch information
alexgg committed Dec 13, 2023
1 parent 77ede04 commit a203bcd
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -o errexit

# shellcheck disable=SC1091
. /usr/libexec/os-helpers-logging
# shellcheck disable=SC1091
. /usr/sbin/balena-config-defaults

old_os_before_hooks=0
old_os_after_hooks=0
Expand Down Expand Up @@ -40,6 +42,15 @@ Options:
EOF
}

DEBUG=$(jq -r '.debug // empty' "${CONFIG_PATH}")
run_hook () {
if [ "${DEBUG}" = "1" ]; then
/bin/sh -x "$1"
else
"$1"
fi
}

# Parse arguments
while [ "$#" -gt "0" ]; do
key=$1
Expand Down Expand Up @@ -85,13 +96,13 @@ list_of_old_os_after_hooks=$(find "${HOOKS_DIR}" -type f | grep after | sort)

if [ "$old_os_before_hooks" = "1" ] ; then
for hook in $list_of_old_os_before_hooks; do
"$hook"
run_hook "$hook"
done
fi

if [ "$forward_hooks" = "1" ] ; then
for hook in $list_of_forward_hooks; do
if ! "$hook" ; then
if ! run_hook "$hook" ; then
forward_cleanup=1
break
fi
Expand All @@ -100,19 +111,19 @@ fi

if [ "$old_os_after_hooks" = "1" ] ; then
for hook in $list_of_old_os_after_hooks; do
"$hook"
run_hook "$hook"
done
fi

if [ "$commit_hooks" = "1" ] ; then
for hook in $list_of_forward_commit_hooks; do
"$hook"
run_hook "$hook"
done
fi

if [ "$forward_cleanup" = "1" ] ; then
for hook in $list_of_forward_cleanup_hooks; do
"$hook"
run_hook "$hook"
done
exit 1
fi

0 comments on commit a203bcd

Please sign in to comment.