File: constants.py

package info (click to toggle)
knot-resolver 6.0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,376 kB
  • sloc: javascript: 42,732; ansic: 40,311; python: 12,580; cpp: 2,121; sh: 1,988; xml: 193; makefile: 181
file content (45 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import importlib.util
import platform
import re
from pathlib import Path

VERSION = "6.0.17"
USER = "knot-resolver"
GROUP = "knot-resolver"

# dirs paths
RUN_DIR = Path("/run/knot-resolver")
ETC_DIR = Path("/etc/knot-resolver")
SBIN_DIR = Path("/usr/sbin")
CACHE_DIR = Path("/var/cache/knot-resolver")

# files paths
CONFIG_FILE = ETC_DIR / "config.yaml"
API_SOCK_FILE = RUN_DIR / "kres-api.sock"

# executables paths
KRESD_EXECUTABLE = SBIN_DIR / "kresd"
KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc"

LINUX_SYS = platform.system() == "Linux"
FREEBSD_SYS = platform.system() == "FreeBSD"

WATCHDOG_LIB = bool(importlib.util.find_spec("watchdog"))
PROMETHEUS_LIB = bool(importlib.util.find_spec("prometheus_client"))


def _freebsd_workers_support() -> bool:
    if FREEBSD_SYS:
        release = platform.release()
        match = re.match(r"(\d+)", release)
        if match:
            return int(match.group(1)) >= 12
    return False


# It is possible to configure multiple kresd workers on Linux systems due to the SO_REUSEPORT socket option.
# FreeBSD version >=12 supports it specifically due to the additional SO_REUSEPORT_LB socket option.
WORKERS_SUPPORT = LINUX_SYS or _freebsd_workers_support()

# Systemd-like NOTIFY message is supported only on Linux systems
NOTIFY_SUPPORT = LINUX_SYS