]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
service manager backend: systemd: added some form of detection that systemd is available
authorVasek Sraier <git@vakabus.cz>
Thu, 8 Apr 2021 15:22:28 +0000 (17:22 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:52 +0000 (16:17 +0200)
manager/integration/tests/basic_crash/run
manager/knot_resolver_manager/kresd_controller/__init__.py
manager/knot_resolver_manager/kresd_controller/systemd/__init__.py

index 35300c590e1772aeeb0063f85d9a6c6b0e9981e4..4634a6f6e4c933b8bfdb4b32e29ded7672a1bb29 100755 (executable)
@@ -18,7 +18,7 @@ systemctl kill --signal=SIGKILL knot-resolver-manager.service
 systemctl start knot-resolver-manager.service
 
 # wait for proper startup
-sleep 1
+sleep 1.5
 
 # run the same test again testing, that instances can start and that the count is correct
 # because there should be kresd instances left after the first run, this tests that the initialization of the manager properly finds them
index 302072312cdd85b12d62484b326c6778cb200eb2..6636186ed200fe91cf4184aaae1a57e5dac071ef 100644 (file)
@@ -4,7 +4,6 @@ from typing import Type
 from knot_resolver_manager.kresd_controller.base import BaseKresdController
 from knot_resolver_manager.kresd_controller.systemd import SystemdKresdController
 
-
 # In this tuple, every supported controller should be listed. In the order of preference (preferred first)
 _registered_controllers = (SystemdKresdController,)
 
index 39b564813005ec39a9d6bc3fa917f4c6e3f52b05..46f96344d85f3e04e69de1f58f5ae63b6435e572 100644 (file)
@@ -1,3 +1,4 @@
+import logging
 from typing import Iterable, List
 
 from knot_resolver_manager import compat
@@ -5,6 +6,8 @@ from knot_resolver_manager.kresd_controller.base import BaseKresdController
 
 from . import dbus_api as systemd
 
+logger = logging.getLogger(__name__)
+
 
 class SystemdKresdController(BaseKresdController):
     async def is_running(self) -> bool:
@@ -21,8 +24,12 @@ class SystemdKresdController(BaseKresdController):
 
     @staticmethod
     async def is_controller_available() -> bool:
-        # TODO: implement a proper check
-        return True
+        try:
+            _ = await compat.asyncio.to_thread(systemd.list_units)
+            return True
+        except BaseException:  # we want every possible exception to be caught
+            logger.warning("systemd DBus API backend failed to initialize", exc_info=True)
+            return False
 
     @staticmethod
     async def get_all_running_instances() -> Iterable["BaseKresdController"]: