Skip to content

Commit

Permalink
greenboot: add feature to disable healthchecks
Browse files Browse the repository at this point in the history
Addresses fedora-iot#119. Allows users to specify healthchecks
to be skipped via a DISABLED_HEALTHCHECKS variable
in greenboot.conf. Skipped healthchecks will be
reflected with an appropriate message in the logs.

Signed-off-by: djach7 <[email protected]>
  • Loading branch information
djach7 committed Apr 9, 2024
1 parent 31354ab commit c4ef2af
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
11 changes: 10 additions & 1 deletion etc/greenboot/greenboot.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ GREENBOOT_WATCHDOG_CHECK_ENABLED=true
### This variable is the number of hours after an upgrade that we consider
### the new deployment as culprit of reboot.
### It has to be a positive integer. Defaults to 24 (hours).
# GREENBOOT_WATCHDOG_GRACE_PERIOD=24
# GREENBOOT_WATCHDOG_GRACE_PERIOD=24

### This variable allows you to specify healthchecks to be skipped.
### The healthcheck must be specified by script name, as in the
### example below. Multiple healthchecks may be skipped by separating
### the script names with spaces.
### NOTE: Script names must be spelled EXACTLY. Typos will result in
### unwanted behaviour.
### DISABLED_HEALTHCHECKS=(01_repository_dns_check.sh 02_watchdog.sh)
DISABLED_HEALTHCHECKS=(01_repository_dns_check.sh)
49 changes: 35 additions & 14 deletions usr/libexec/greenboot/greenboot
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,49 @@ SCRIPTS_CHECK_PATHS=("/usr/lib/greenboot/check" "/etc/greenboot/check")
SCRIPTS_GREEN_PATHS=("/usr/lib/greenboot/green.d" "/etc/greenboot/green.d")
SCRIPTS_RED_PATHS=("/usr/lib/greenboot/red.d" "/etc/greenboot/red.d")

source_configuration_file() {
GREENBOOT_CONFIGURATION_FILE=/etc/greenboot/greenboot.conf
if test -f "$GREENBOOT_CONFIGURATION_FILE"; then
# shellcheck source=/etc/greenboot/greenboot.conf
source $GREENBOOT_CONFIGURATION_FILE
fi
}

source_configuration_file
function is_disabled {
HEALTHCHECK=$1
for DISABLED_HEALTHCHECK in "${DISABLED_HEALTHCHECKS[@]}"; do
if [ "${HEALTHCHECK}" == "${DISABLED_HEALTHCHECK}" ]; then return 0; fi
done
return 1
}

script_runner () {
local scripts_dir=$1; shift
local mode=$1; shift
local start_msg=$1; shift
local required_hc_failed=false
echo "$start_msg"
for script in $(find "$scripts_dir" -name '*.sh' | sort); do
local rc=0
systemd-cat -t "$(basename "$script")" bash "$script" || rc=$?
if [ $rc -ne 0 ]; then
local failure_msg
failure_msg="Script '$(basename "$script")' FAILURE (exit code '$rc')"
case "$mode" in
"relaxed")
echo "<2>$failure_msg. Continuing..." >&2
;;
"strict")
required_hc_failed=true
echo "<0>$failure_msg. Continuing..." >&2
esac
if is_disabled "$(basename "$script")"; then
echo "'$(basename "$script")' was skipped, as specified in config"
else
echo "<6>Script '$(basename "$script")' SUCCESS"
local rc=0
systemd-cat -t "$(basename "$script")" bash "$script" || rc=$?
if [ $rc -ne 0 ]; then
local failure_msg
failure_msg="Script '$(basename "$script")' FAILURE (exit code '$rc')"
case "$mode" in
"relaxed")
echo "<2>$failure_msg. Continuing..." >&2
;;
"strict")
required_hc_failed=true
echo "<0>$failure_msg. Continuing..." >&2
esac
else
echo "<6>Script '$(basename "$script")' SUCCESS"
fi
fi
done

Expand Down

0 comments on commit c4ef2af

Please sign in to comment.