Blame SOURCES/0013-Add-service-check-dependencies.patch

235f5a
From 235198b41a0932a7a190124fff5f8c1afa5d6679 Mon Sep 17 00:00:00 2001
235f5a
From: Rob Crittenden <rcritten@redhat.com>
235f5a
Date: Wed, 5 May 2021 15:35:19 -0400
235f5a
Subject: [PATCH] Add service check dependencies
235f5a
235f5a
Since 389-ds is the heart of IPA there may not be a point in checking
235f5a
all dependent services. ipa-dnskeysyncd in particular doesn't like
235f5a
when it can't connect and tries to restart itself multiple times.
235f5a
235f5a
Note that this currently works because the services are sorted
235f5a
alphabetically and dirsrv appears near the top. Re-ordering may be
235f5a
necessary in the future.
235f5a
235f5a
I'm choosing not to add dirsrv to the other services because they
235f5a
return cleanly if it is not available.
235f5a
235f5a
https://bugzilla.redhat.com/show_bug.cgi?id=1776687
235f5a
235f5a
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
235f5a
---
235f5a
 src/ipahealthcheck/core/core.py     | 20 ++++++++++++++++++++
235f5a
 src/ipahealthcheck/meta/services.py |  2 ++
235f5a
 2 files changed, 22 insertions(+)
235f5a
235f5a
diff --git a/src/ipahealthcheck/core/core.py b/src/ipahealthcheck/core/core.py
235f5a
index a4af690..eaa2d9c 100644
235f5a
--- a/src/ipahealthcheck/core/core.py
235f5a
+++ b/src/ipahealthcheck/core/core.py
235f5a
@@ -81,6 +81,26 @@ def run_service_plugins(plugins, source, check):
235f5a
         if not isinstance(plugin, ServiceCheck):
235f5a
             continue
235f5a
 
235f5a
+        # Try to save some time to not check dependent services if the
235f5a
+        # parent is down.
235f5a
+        if not set(plugin.requires).issubset(available):
235f5a
+            # A required service is not available. Either it hasn't been
235f5a
+            # checked yet or it isn't running. If not running break.
235f5a
+            running = True
235f5a
+            for result in results.results:
235f5a
+                if result.check in plugin.requires:
235f5a
+                    # if not in available but in results the service failed
235f5a
+                    running = False
235f5a
+                    break
235f5a
+            if not running:
235f5a
+                logger.debug(
235f5a
+                    'Skipping %s:%s because %s service(s) not running',
235f5a
+                    plugin.__class__.__module__,
235f5a
+                    plugin.__class__.__name__,
235f5a
+                    ', '.join(set(plugin.requires) - set(available))
235f5a
+                )
235f5a
+                continue
235f5a
+
235f5a
         logger.debug('Calling check %s', plugin)
235f5a
         for result in plugin.check():
235f5a
             # always run the service checks so dependencies work
235f5a
diff --git a/src/ipahealthcheck/meta/services.py b/src/ipahealthcheck/meta/services.py
235f5a
index a987108..5d80728 100644
235f5a
--- a/src/ipahealthcheck/meta/services.py
235f5a
+++ b/src/ipahealthcheck/meta/services.py
235f5a
@@ -92,6 +92,8 @@ class ipa_dnskeysyncd(IPAServiceCheck):
235f5a
     def check(self):
235f5a
         self.service_name = 'ipa-dnskeysyncd'
235f5a
 
235f5a
+        requires = ('dirsrv',)
235f5a
+
235f5a
         if not bindinstance.named_conf_exists():
235f5a
             return ()
235f5a
 
235f5a
-- 
235f5a
2.31.1
235f5a