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")
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
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:
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
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:
kresd_cache_dir,
kresd_config_file_supervisord_pattern,
kresd_executable,
+ policy_loader_config_file,
supervisord_config_file,
supervisord_config_file_tmp,
supervisord_pid_file,
@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))
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:
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())
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))
loglevel = {{ config.loglevel }}
{# there are more options in the plugin section #}
-
[unix_http_server]
file = {{ config.unix_http_server }}
[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 }}
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 }}
startsecs=0
environment={{ gc.environment }}
stdout_logfile=NONE
-stderr_logfile=NONE
\ No newline at end of file
+stderr_logfile=NONE