diff options
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/info/extras.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/kvmd/apps/kvmd/info/extras.py b/kvmd/apps/kvmd/info/extras.py index 6024aebc..10d57f27 100644 --- a/kvmd/apps/kvmd/info/extras.py +++ b/kvmd/apps/kvmd/info/extras.py @@ -23,6 +23,7 @@ import os import contextlib +from typing import Tuple from typing import Dict from typing import Optional @@ -67,7 +68,7 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager): def __rewrite_app_daemon(self, extras: Dict) -> None: daemon = extras.get("daemon", "") if isinstance(daemon, str) and daemon.strip(): - extras["enabled"] = self.__is_daemon_enabled(daemon) + (extras["enabled"], extras["started"]) = self.__get_daemon_status(daemon) def __rewrite_app_port(self, extras: Dict) -> None: port_path = extras.get("port", "") @@ -79,25 +80,23 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager): if isinstance(config, int): extras["port"] = config - def __is_daemon_enabled(self, name: str) -> bool: + def __get_daemon_status(self, name: str) -> Tuple[bool, bool]: if not name.endswith(".service"): name += ".service" - try: with contextlib.closing(dbus.SystemBus()) as bus: systemd = bus.get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1") # pylint: disable=no-member manager = dbus.Interface(systemd, dbus_interface="org.freedesktop.systemd1.Manager") - try: unit_proxy = bus.get_object("org.freedesktop.systemd1", manager.GetUnit(name)) # pylint: disable=no-member unit_properties = dbus.Interface(unit_proxy, dbus_interface="org.freedesktop.DBus.Properties") - enabled = (unit_properties.Get("org.freedesktop.systemd1.Unit", "ActiveState") == "active") + started = (unit_properties.Get("org.freedesktop.systemd1.Unit", "ActiveState") == "active") except dbus.exceptions.DBusException as err: if "NoSuchUnit" not in str(err): raise - enabled = False - - return (enabled or (manager.GetUnitFileState(name) in ["enabled", "enabled-runtime", "static", "indirect", "generated"])) + started = False + enabled = (manager.GetUnitFileState(name) in ["enabled", "enabled-runtime", "static", "indirect", "generated"]) + return (enabled, started) except Exception as err: get_logger(0).error("Can't get info about the service %r: %s", name, tools.efmt(err)) - return True + return (True, True) |