return self._last_used_config_strict
async def _instability_handler(self) -> None:
- logger.error("Instability callback invoked. No idea how to react, performing suicide. See you later!")
+ logger.error(
+ "Instability callback invoked. Something is wrong, no idea how to react."
+ " Performing suicide. See you later!"
+ )
sys.exit(1)
async def _watchdog(self) -> None:
async def get_all_running_instances(self) -> Iterable[Subprocess]:
res: List[SystemdSubprocess] = []
- units = await compat.asyncio.to_thread(systemd.list_unit_names, self._systemd_type)
+ units = await compat.asyncio.to_thread(systemd.list_units, self._systemd_type)
for unit in units:
- u: str = unit
- if u.startswith("kresd") and u.endswith(".service"):
- iden = u.replace("kresd", "")[1:].replace(".service", "")
- persistance_type = SystemdPersistanceType.PERSISTENT if "@" in u else SystemdPersistanceType.TRANSIENT
+ if unit.name.startswith("kresd") and unit.name.endswith(".service"):
+ iden = unit.name.replace("kresd", "")[1:].replace(".service", "")
+ persistance_type = (
+ SystemdPersistanceType.PERSISTENT if "@" in unit.name else SystemdPersistanceType.TRANSIENT
+ )
+
+ if unit.state == "failed":
+ # if a unit is failed, remove it from the system by reseting its state
+ # should work for both transient and persistent units
+ logger.warning("Unit '%s' is already failed, resetting its state and ignoring it", unit.name)
+ await compat.asyncio.to_thread(systemd.reset_failed_unit, self._systemd_type, unit.name)
+ continue
+
res.append(
SystemdSubprocess(
SubprocessType.KRESD,
persistance_type,
)
)
- elif u == "kres-cache-gc.service":
+ elif unit.name == "kres-cache-gc.service":
+ # we can't easily check, if the unit is transient or not without additional systemd call
+ # we ignore it for now and assume the default persistency state. It shouldn't cause any
+ # problems, because interactions with the process are done the same way in all cases
res.append(SystemdSubprocess(SubprocessType.GC, alloc(), self._systemd_type))
return res
return [str(u[0]) for u in _list_units_internal(type_)]
-def list_failed_unit_names(type_: SystemdType) -> List[str]:
- return [str(u[0]) for u in _list_units_internal(type_) if str(u[3]) == "failed"]
+def reset_failed_unit(typ: SystemdType, unit_name: str):
+ systemd = _create_manager_proxy(typ)
+ systemd.ResetFailedUnit(unit_name)
def restart_unit(type_: SystemdType, unit_name: str):