From bf026adf9f0d294630ee6dcac7fa2b64a3c120f4 Mon Sep 17 00:00:00 2001 From: Vasek Sraier Date: Thu, 31 Mar 2022 14:31:46 +0200 Subject: [PATCH] subprocess manament: remove configuration files of kresd's even when not stopped directly --- manager/knot_resolver_manager/kres_manager.py | 2 ++ .../knot_resolver_manager/kresd_controller/interface.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/manager/knot_resolver_manager/kres_manager.py b/manager/knot_resolver_manager/kres_manager.py index c479db09e..b444fa996 100644 --- a/manager/knot_resolver_manager/kres_manager.py +++ b/manager/knot_resolver_manager/kres_manager.py @@ -218,6 +218,8 @@ class KresManager: # pylint: disable=too-many-instance-attributes # we could stop all the children one by one right now # we won't do that and we leave that up to the subprocess controller to do that while it is shutting down await self._controller.shutdown_controller() + # now, when everything is stopped, let's clean up all the remains + await asyncio.gather(*[w.cleanup() for w in self._workers]) async def forced_shutdown(self) -> None: logger.warning("Collecting all remaining workers...") diff --git a/manager/knot_resolver_manager/kresd_controller/interface.py b/manager/knot_resolver_manager/kresd_controller/interface.py index 3aa08f6ef..796704237 100644 --- a/manager/knot_resolver_manager/kresd_controller/interface.py +++ b/manager/knot_resolver_manager/kresd_controller/interface.py @@ -133,6 +133,13 @@ class Subprocess: if self._metrics_registered: unregister_resolver_metrics_for(self) await self._stop() + await self.cleanup() + + async def cleanup(self) -> None: + """ + Remove temporary files and all traces of this instance running. It is NOT SAFE to call this while + the kresd is running, because it will break automatic restarts (at the very least). + """ kresd_config_file(self._config, self.id).unlink() def __eq__(self, o: object) -> bool: -- 2.47.3