Avoid running health checks if conditions aren't met

Resolves: rhbz#2120593

Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
This commit is contained in:
Peter Robinson 2022-09-08 16:16:16 +01:00
parent 9e6d067d85
commit 7b1535561b
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,46 @@
From 2c0ac48ec6fd620816da4e240d9a2310922786d6 Mon Sep 17 00:00:00 2001
From: Antonio Murdaca <runcom@linux.com>
Date: Thu, 8 Sep 2022 14:20:30 +0200
Subject: [PATCH] avoid running checks if conditions aren't met
Signed-off-by: Antonio Murdaca <runcom@linux.com>
---
.../greenboot/check/required.d/01_repository_dns_check.sh | 5 +++++
usr/lib/greenboot/check/required.d/02_watchdog.sh | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/usr/lib/greenboot/check/required.d/01_repository_dns_check.sh b/usr/lib/greenboot/check/required.d/01_repository_dns_check.sh
index f661dcd..51e52b3 100644
--- a/usr/lib/greenboot/check/required.d/01_repository_dns_check.sh
+++ b/usr/lib/greenboot/check/required.d/01_repository_dns_check.sh
@@ -44,6 +44,11 @@ if [[ ! -d $REPOS_DIRECTORY ]]; then
exit 1
fi
+if [ -z "$(ls -A $REPOS_DIRECTORY)" ]; then
+ echo "${REPOS_DIRECTORY} is empty, skipping check"
+ exit 0
+fi
+
get_domain_names_from_platform_urls
if [[ -n $DOMAIN_NAMES ]]; then
get_dns_resolution_from_domain_names
diff --git a/usr/lib/greenboot/check/required.d/02_watchdog.sh b/usr/lib/greenboot/check/required.d/02_watchdog.sh
index 101750d..b072288 100644
--- a/usr/lib/greenboot/check/required.d/02_watchdog.sh
+++ b/usr/lib/greenboot/check/required.d/02_watchdog.sh
@@ -41,6 +41,11 @@ check_if_current_boot_is_wd_triggered() {
fi
}
+if ! check_if_there_is_a_watchdog ; then
+ echo "No watchdog on the system, skipping check"
+ exit 0
+fi
+
# This is in order to test check_if_current_boot_is_wd_triggered
# function within a container
if [ "${1}" != "--source-only" ]; then
--
2.37.3

View File

@ -2,7 +2,7 @@
Name: greenboot
Version: 0.15.1
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Generic Health Check Framework for systemd
License: LGPLv2+
@ -13,6 +13,7 @@ License: LGPLv2+
URL: https://github.com/%{repo_owner}/%{repo_name}
Source0: https://github.com/%{repo_owner}/%{repo_name}/archive/%{repo_tag}.tar.g#/%{name}-%{version}.tar.gz
Patch0: 0001-disable-DefaultDependencies-to-fix-cycle-error.patch
Patch1: 0001-avoid-running-checks-if-conditions-aren-t-met.patch
ExcludeArch: s390x
BuildRequires: systemd-rpm-macros
@ -172,6 +173,9 @@ install -DpZm 0644 etc/greenboot/greenboot.conf %{buildroot}%{_sysconfdir}/%{nam
%{_prefix}/lib/%{name}/check/required.d/02_watchdog.sh
%changelog
* Thu Sep 08 2022 Peter Robinson <pbrobinson@fedoraproject.org> - 0.15.1-3
- Avoid running health checks if conditions aren't met
* Wed Aug 31 2022 Peter Robinson <pbrobinson@fedoraproject.org> - 0.15.1-2
- disable DefaultDependencies to fix cycle error