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
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,)
+import logging
from typing import Iterable, List
from knot_resolver_manager import compat
from . import dbus_api as systemd
+logger = logging.getLogger(__name__)
+
class SystemdKresdController(BaseKresdController):
async def is_running(self) -> bool:
@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"]: