]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: more startup logging and small supervisord detection optimization
authorVasek Sraier <git@vakabus.cz>
Sat, 18 Jun 2022 21:55:50 +0000 (23:55 +0200)
committerVaclav Sraier <vaclav.sraier@nic.cz>
Fri, 24 Jun 2022 13:22:07 +0000 (13:22 +0000)
manager/knot_resolver_manager/kres_manager.py
manager/knot_resolver_manager/kresd_controller/interface.py
manager/knot_resolver_manager/kresd_controller/supervisord/__init__.py

index de6066153e3544534ae73c8c6307fc14413360e4..5e978d86fea8a6b401ca5cfd42db3b2972dfa960 100644 (file)
@@ -107,8 +107,10 @@ class KresManager:  # pylint: disable=too-many-instance-attributes
         else:
             self._controller = selected_controller
         self._config_store = config_store
+        logger.debug("Starting controller")
         await self._controller.initialize_controller(config_store.get())
         self._watchdog_task = create_task(self._watchdog())
+        logger.debug("Looking for already running workers")
         await self._collect_already_running_workers()
 
         # registering the function calls them immediately, therefore after this, the config is applied
index 796704237a5de5423373cbf0cb3ed44f74a57fc4..df5ebd741cb98a32a037b306ed9bd98749776a5f 100644 (file)
@@ -1,5 +1,6 @@
 import asyncio
 import itertools
+import logging
 import sys
 from enum import Enum, auto
 from typing import Dict, Iterable, Optional, Type, TypeVar
@@ -11,6 +12,8 @@ from knot_resolver_manager.exceptions import SubprocessControllerException
 from knot_resolver_manager.statistics import register_resolver_metrics_for, unregister_resolver_metrics_for
 from knot_resolver_manager.utils.async_utils import writefile
 
+logger = logging.getLogger(__name__)
+
 
 class SubprocessType(Enum):
     KRESD = auto()
@@ -124,9 +127,11 @@ class Subprocess:
     async def apply_new_config(self, new_config: KresConfig) -> None:
         self._config = new_config
         # update config file
+        logger.debug(f"Writing config file for {self.id}")
         lua_config = new_config.render_lua()
         await writefile(kresd_config_file(new_config, self.id), lua_config)
         # update runtime status
+        logger.debug(f"Restarting {self.id}")
         await self._restart()
 
     async def stop(self) -> None:
index 2fa571f8dabd7c1f91721656a4cafbaa5023203a..f125ad97065e9520c2f5a5e917dce1782fb4edf6 100644 (file)
@@ -1,3 +1,4 @@
+import asyncio
 import logging
 from os import kill
 from pathlib import Path
@@ -25,8 +26,10 @@ logger = logging.getLogger(__name__)
 
 
 async def _start_supervisord(config: KresConfig) -> None:
+    logger.debug("Writing supervisord config")
     await write_config_file(config)
-    res = await call(f'supervisord --configuration="{supervisord_config_file(config).absolute()}"', shell=True)
+    logger.debug("Starting supervisord")
+    res = await call(["supervisord", "--configuration", str(supervisord_config_file(config).absolute())])
     if res != 0:
         raise SubprocessControllerException(f"Supervisord exited with exit code {res}")
 
@@ -53,9 +56,11 @@ def _stop_supervisord(config: KresConfig) -> None:
 
 
 async def _is_supervisord_available() -> bool:
-    i = await call("supervisorctl -h > /dev/null", shell=True, discard_output=True)
-    i += await call("supervisord -h > /dev/null", shell=True, discard_output=True)
-    return i == 0
+    i, y = await asyncio.gather(
+        call("supervisorctl -h > /dev/null", shell=True, discard_output=True),
+        call("supervisord -h > /dev/null", shell=True, discard_output=True),
+    )
+    return i + y == 0
 
 
 async def _get_supervisord_pid(config: KresConfig) -> Optional[int]: