summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-04-17 15:41:05 +0300
committerDevaev Maxim <[email protected]>2021-04-17 15:41:05 +0300
commitbe012fd38d6f6f2d269dcbffd3aafe59a2a9a40c (patch)
tree0742bf1e2934f8d882e9e7b3c81360d7204285ee /kvmd
parent3a2ffcfd5c0591160333d1b347880f09eb2ee056 (diff)
terminal window
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/info/extras.py17
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)