From: Aleš Mrázek Date: Mon, 16 Sep 2024 10:59:36 +0000 (+0200) Subject: python: use CACHE_DIR and RUN_DIR constants X-Git-Tag: v6.0.9~9^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87d3a7c5633cd2286f4982c34d16af7b9d81cad2;p=thirdparty%2Fknot-resolver.git python: use CACHE_DIR and RUN_DIR constants --- diff --git a/etc/config/config.dev.yaml b/etc/config/config.dev.yaml index 1ceddfb38..6705069e3 100644 --- a/etc/config/config.dev.yaml +++ b/etc/config/config.dev.yaml @@ -1,9 +1,6 @@ -rundir: ./runtime workers: 1 management: interface: 127.0.0.1@5000 -cache: - storage: ./cache logging: level: notice groups: diff --git a/python/constants.py.in b/python/constants.py.in index 39de89a0f..3f2eb734f 100644 --- a/python/constants.py.in +++ b/python/constants.py.in @@ -5,9 +5,10 @@ USER = "@user@" GROUP = "@group@" # dirs paths -RUN_DIR = Path("@run_dir@") +RUN_DIR = Path("@prefix@@run_dir@") ETC_DIR = Path("@etc_dir@") SBIN_DIR = Path("@sbin_dir@") +CACHE_DIR = Path("@cache_dir@") # files paths CONFIG_FILE = ETC_DIR / "config.yaml" diff --git a/python/knot_resolver/constants.py b/python/knot_resolver/constants.py index fb45c26b6..5288b519b 100644 --- a/python/knot_resolver/constants.py +++ b/python/knot_resolver/constants.py @@ -8,15 +8,12 @@ GROUP = "knot-resolver" RUN_DIR = Path("/run/knot-resolver") ETC_DIR = Path("/etc/knot-resolver") SBIN_DIR = Path("/usr/bin") +CACHE_DIR = Path("/var/cache/knot-resolver") # files paths CONFIG_FILE = ETC_DIR / "config.yaml" API_SOCK_FILE = RUN_DIR / "kres-api.sock" -# environmental variables -CONFIG_FILE_ENV_VAR = "KRES_CONFIG_FILE" -API_SOCK_FILE_ENV_VAR = "KRES_API_SOCK_FILE" - # executables paths KRESD_EXECUTABLE = SBIN_DIR / "kresd" KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc" diff --git a/python/knot_resolver/datamodel/cache_schema.py b/python/knot_resolver/datamodel/cache_schema.py index 3f7d1dc22..d40ee2a0f 100644 --- a/python/knot_resolver/datamodel/cache_schema.py +++ b/python/knot_resolver/datamodel/cache_schema.py @@ -1,5 +1,6 @@ from typing import List, Literal, Optional, Union +from knot_resolver.constants import CACHE_DIR from knot_resolver.datamodel.templates import template_from_str from knot_resolver.datamodel.types import ( DNSRecordTypeEnum, @@ -123,7 +124,7 @@ class CacheSchema(ConfigSchema): prefetch: These options help keep the cache hot by prefetching expiring records or learning usage patterns and repetitive queries. """ - storage: WritableDir = lazy_default(WritableDir, "/var/cache/knot-resolver") + storage: WritableDir = lazy_default(WritableDir, str(CACHE_DIR)) size_max: SizeUnit = SizeUnit("100M") garbage_collector: Union[GarbageCollectorSchema, Literal[False]] = GarbageCollectorSchema() ttl_min: TimeUnit = TimeUnit("5s") diff --git a/python/knot_resolver/datamodel/config_schema.py b/python/knot_resolver/datamodel/config_schema.py index 4e3d8b3d1..ddadd7fb5 100644 --- a/python/knot_resolver/datamodel/config_schema.py +++ b/python/knot_resolver/datamodel/config_schema.py @@ -239,7 +239,7 @@ def get_rundir_without_validation(data: Dict[str, Any]) -> WritableDir: Used for initial manager startup. """ - return WritableDir(data["rundir"] if "rundir" in data else RUN_DIR, object_path="/rundir") + return WritableDir(data["rundir"] if "rundir" in data else str(RUN_DIR), object_path="/rundir") def kres_config_json_schema() -> Dict[str, Any]: diff --git a/python/meson.build b/python/meson.build index f6539e515..a0ea0c066 100644 --- a/python/meson.build +++ b/python/meson.build @@ -5,9 +5,11 @@ constants_config = configuration_data() constants_config.set('version', meson.project_version()) constants_config.set('user', user) constants_config.set('group', group) +constants_config.set('prefix', prefix) constants_config.set('run_dir', run_dir) constants_config.set('etc_dir', etc_dir) constants_config.set('sbin_dir', sbin_dir) +constants_config.set('cache_dir', systemd_cache_dir) configure_file( input: 'constants.py.in',