From: Vasek Sraier Date: Sat, 18 Jun 2022 21:55:50 +0000 (+0200) Subject: manager: more startup logging and small supervisord detection optimization X-Git-Tag: v6.0.0a1~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbc114e5abb6d30fdf363988e723e9feceafeeb0;p=thirdparty%2Fknot-resolver.git manager: more startup logging and small supervisord detection optimization --- diff --git a/manager/knot_resolver_manager/kres_manager.py b/manager/knot_resolver_manager/kres_manager.py index de6066153..5e978d86f 100644 --- a/manager/knot_resolver_manager/kres_manager.py +++ b/manager/knot_resolver_manager/kres_manager.py @@ -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 diff --git a/manager/knot_resolver_manager/kresd_controller/interface.py b/manager/knot_resolver_manager/kresd_controller/interface.py index 796704237..df5ebd741 100644 --- a/manager/knot_resolver_manager/kresd_controller/interface.py +++ b/manager/knot_resolver_manager/kresd_controller/interface.py @@ -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: diff --git a/manager/knot_resolver_manager/kresd_controller/supervisord/__init__.py b/manager/knot_resolver_manager/kresd_controller/supervisord/__init__.py index 2fa571f8d..f125ad970 100644 --- a/manager/knot_resolver_manager/kresd_controller/supervisord/__init__.py +++ b/manager/knot_resolver_manager/kresd_controller/supervisord/__init__.py @@ -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]: