From: Aleš Mrázek Date: Tue, 12 Mar 2024 14:50:10 +0000 (+0100) Subject: manager: controller: policy-loader program added X-Git-Tag: v6.0.8~8^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=399c521b3a6a07bed485397d197881e1489e6368;p=thirdparty%2Fknot-resolver.git manager: controller: policy-loader program added --- diff --git a/manager/knot_resolver_manager/constants.py b/manager/knot_resolver_manager/constants.py index 2d9ebd23d..90ceed9f8 100644 --- a/manager/knot_resolver_manager/constants.py +++ b/manager/knot_resolver_manager/constants.py @@ -39,6 +39,10 @@ def kresd_cache_dir(config: "KresConfig") -> Path: return config.cache.storage.to_path() +def policy_loader_config_file(_config: "KresConfig") -> Path: + return Path("policy-loader.conf") + + def kresd_config_file(_config: "KresConfig", kres_id: "KresID") -> Path: return Path(f"kresd{int(kres_id)}.conf") diff --git a/manager/knot_resolver_manager/kresd_controller/interface.py b/manager/knot_resolver_manager/kresd_controller/interface.py index bc7708721..25bf00ac3 100644 --- a/manager/knot_resolver_manager/kresd_controller/interface.py +++ b/manager/knot_resolver_manager/kresd_controller/interface.py @@ -10,7 +10,7 @@ from pathlib import Path from typing import Dict, Iterable, Optional, Type, TypeVar from weakref import WeakValueDictionary -from knot_resolver_manager.constants import kresd_config_file +from knot_resolver_manager.constants import kresd_config_file, policy_loader_config_file from knot_resolver_manager.datamodel.config_schema import KresConfig from knot_resolver_manager.exceptions import SubprocessControllerException from knot_resolver_manager.kresd_controller.registered_workers import register_worker, unregister_worker @@ -115,7 +115,7 @@ class Subprocess(ABC): await writefile(config_file, config_lua) elif self.type is SubprocessType.POLICY_LOADER: config_lua = self._config.render_lua_policy() - config_file = Path("policy-loader.conf") + config_file = policy_loader_config_file(self._config) await writefile(config_file, config_lua) try: @@ -141,7 +141,7 @@ class Subprocess(ABC): await writefile(config_file, config_lua) elif self.type is SubprocessType.POLICY_LOADER: config_lua = self._config.render_lua_policy() - config_file = Path("policy-loader.conf") + config_file = policy_loader_config_file(self._config) await writefile(config_file, config_lua) # update runtime status @@ -164,7 +164,7 @@ class Subprocess(ABC): config_file = kresd_config_file(self._config, self.id) config_file.unlink() elif self.type is SubprocessType.POLICY_LOADER: - config_file = Path("policy-loader.conf") + config_file = policy_loader_config_file(self._config) config_file.unlink() def __eq__(self, o: object) -> bool: diff --git a/manager/knot_resolver_manager/kresd_controller/supervisord/config_file.py b/manager/knot_resolver_manager/kresd_controller/supervisord/config_file.py index fab0a1430..15a81ba7e 100644 --- a/manager/knot_resolver_manager/kresd_controller/supervisord/config_file.py +++ b/manager/knot_resolver_manager/kresd_controller/supervisord/config_file.py @@ -10,6 +10,7 @@ from knot_resolver_manager.constants import ( kresd_cache_dir, kresd_config_file_supervisord_pattern, kresd_executable, + policy_loader_config_file, supervisord_config_file, supervisord_config_file_tmp, supervisord_pid_file, @@ -32,9 +33,11 @@ class SupervisordKresID(KresID): @staticmethod def from_string(val: str) -> "SupervisordKresID": + # the double name is checked because thats how we read it from supervisord if val in ("cache-gc", "cache-gc:cache-gc"): - # the double name is checked because thats how we read it from supervisord return SupervisordKresID.new(SubprocessType.GC, 0) + elif val in ("policy-loader", "policy-loader:policy-loader"): + return SupervisordKresID.new(SubprocessType.POLICY_LOADER, 0) else: val = val.replace("kresd:kresd", "") return SupervisordKresID.new(SubprocessType.KRESD, int(val)) @@ -42,6 +45,8 @@ class SupervisordKresID(KresID): def __str__(self) -> str: if self.subprocess_type is SubprocessType.GC: return "cache-gc" + elif self.subprocess_type is SubprocessType.POLICY_LOADER: + return "policy-loader" elif self.subprocess_type is SubprocessType.KRESD: return f"kresd:kresd{self._id}" else: @@ -94,6 +99,16 @@ class ProcessTypeConfig: environment="", ) + @staticmethod + def create_policy_loader_config(config: KresConfig) -> "ProcessTypeConfig": + cwd = str(os.getcwd()) + return ProcessTypeConfig( # type: ignore[call-arg] + logfile=supervisord_subprocess_log_dir(config) / "policy-loader.log", + workdir=cwd, + command=f"{kresd_executable()} -c {(policy_loader_config_file(config))} -c - -n", + environment="X-SUPERVISORD-TYPE=notify", + ) + @staticmethod def create_kresd_config(config: KresConfig) -> "ProcessTypeConfig": cwd = str(os.getcwd()) @@ -172,11 +187,11 @@ async def write_config_file(config: KresConfig) -> None: template = template.decode("utf8") config_string = Template(template).render( gc=ProcessTypeConfig.create_gc_config(config), + loader=ProcessTypeConfig.create_policy_loader_config(config), kresd=ProcessTypeConfig.create_kresd_config(config), manager=ProcessTypeConfig.create_manager_config(config), config=SupervisordConfig.create(config), ) - print(config_string) await writefile(supervisord_config_file_tmp(config), config_string) # atomically replace (we don't technically need this right now, but better safe then sorry) os.rename(supervisord_config_file_tmp(config), supervisord_config_file(config)) diff --git a/manager/knot_resolver_manager/kresd_controller/supervisord/supervisord.conf.j2 b/manager/knot_resolver_manager/kresd_controller/supervisord/supervisord.conf.j2 index dcbb645d9..b1fed1aa1 100644 --- a/manager/knot_resolver_manager/kresd_controller/supervisord/supervisord.conf.j2 +++ b/manager/knot_resolver_manager/kresd_controller/supervisord/supervisord.conf.j2 @@ -12,7 +12,6 @@ silent = true loglevel = {{ config.loglevel }} {# there are more options in the plugin section #} - [unix_http_server] file = {{ config.unix_http_server }} @@ -37,8 +36,6 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [rpcinterface:fast] supervisor.rpcinterface_factory = knot_resolver_manager.kresd_controller.supervisord.plugin.fast_rpcinterface:make_main_rpcinterface - - [program:manager] redirect_stderr=false directory={{ manager.workdir }} @@ -71,6 +68,17 @@ environment={{ kresd.environment }} stdout_logfile=NONE stderr_logfile=NONE +[program:policy-loader] +directory={{ loader.workdir }} +command={{ loader.command }} +autostart=false +stopsignal=TERM +killasgroup=true +startsecs=300 +environment={{ loader.environment }} +stdout_logfile=NONE +stderr_logfile=NONE + [program:cache-gc] redirect_stderr=false directory={{ gc.workdir }} @@ -82,4 +90,4 @@ killasgroup=true startsecs=0 environment={{ gc.environment }} stdout_logfile=NONE -stderr_logfile=NONE \ No newline at end of file +stderr_logfile=NONE