]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
python: config/templates: added supervisord config template
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 10 Feb 2026 13:55:54 +0000 (14:55 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Thu, 26 Mar 2026 13:13:29 +0000 (14:13 +0100)
python/knot_resolver/config/templates/__init__.py [new file with mode: 0644]
python/knot_resolver/config/templates/supervisord.conf.j2 [new file with mode: 0644]
setup.py

diff --git a/python/knot_resolver/config/templates/__init__.py b/python/knot_resolver/config/templates/__init__.py
new file mode 100644 (file)
index 0000000..3bcdefd
--- /dev/null
@@ -0,0 +1,33 @@
+from __future__ import annotations
+
+from pathlib import Path
+
+from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template
+
+
+def _get_templates_path() -> Path:
+    templates_path = Path(__file__).resolve().parent
+    if not templates_path.exists():
+        raise FileNotFoundError(templates_path)
+    if not templates_path.is_dir():
+        raise NotADirectoryError(templates_path)
+    return templates_path
+
+
+_TEMPLATES_PATH: Path = _get_templates_path()
+
+
+def _load_template_from_str(template: str) -> Template:
+    loader = FileSystemLoader(_TEMPLATES_PATH)
+    env = Environment(trim_blocks=True, lstrip_blocks=True, loader=loader, undefined=StrictUndefined)
+    return env.from_string(template)
+
+
+def _import_template(template: str) -> Template:
+    template_file = _TEMPLATES_PATH / template
+    with template_file.open() as file:
+        template = file.read()
+    return _load_template_from_str(template)
+
+
+SUPERVISORD_TEMPLATE: Template = _import_template("supervisord.conf.j2")
diff --git a/python/knot_resolver/config/templates/supervisord.conf.j2 b/python/knot_resolver/config/templates/supervisord.conf.j2
new file mode 100644 (file)
index 0000000..c55d2de
--- /dev/null
@@ -0,0 +1,72 @@
+[supervisord]
+directory = {{ supervisord.workdir }}
+pidfile = {{ supervisord.pidfile }}
+logfile = {{ supervisord.logfile }}
+logfile_maxbytes = 0
+loglevel = {{ supervisord.loglevel }}
+nodaemon = true
+silent = true
+
+[supervisorctl]
+serverurl = unix://{{ supervisord.unix_http_server }}
+
+[unix_http_server]
+file = {{ supervisord.unix_http_server }}
+
+[program:manager]
+command = {{ manager.command }}
+directory = {{ manager.workdir }}
+environment = {{ manager.environment }}
+startsecs= {{ manager.startsecs }}
+redirect_stderr = false
+autostart = true
+autorestart = true
+killasgroup = true
+stopsignal = SIGTERM
+stopwaitsecs = 30
+stdout_logfile = NONE
+stderr_logfile = NONE
+
+[program:worker]
+process_name = %(program_name)s%(process_num)d
+numprocs = {{ worker.max_procs }}
+command = {{ worker.command }}
+directory = {{ worker.workdir }}
+environment = {{ worker.environment }}
+startsecs = {{ worker.startsecs }}
+redirect_stderr = false
+autostart = false
+autorestart = true
+killasgroup = true
+stopsignal = SIGTERM
+stopwaitsecs = 30
+stdout_logfile = NONE
+stderr_logfile = NONE
+
+[program:loader]
+command = {{ loader.command }}
+directory = {{ loader.workdir }}
+environment = {{ loader.environment }}
+startsecs = {{ loader.startsecs }}
+redirect_stderr = false
+autostart = false
+exitcodes = 0
+killasgroup = true
+stopsignal = SIGTERM
+stopwaitsecs = 30
+stdout_logfile = NONE
+stderr_logfile = NONE
+
+[program:cache-gc]
+command = {{ cache_gc.command }}
+directory = {{ cache_gc.workdir }}
+environment = {{ cache_gc.environment }}
+startsecs={{ cache_gc.startsecs }}
+redirect_stderr=false
+autostart=false
+autorestart=true
+killasgroup=true
+stopsignal = SIGTERM
+stopwaitsecs = 30
+stdout_logfile=NONE
+stderr_logfile=NONE
index bf9fe434b19bfeb7c30b93642980930ddd191b18..241a53ba4cb6eb5d20f3a7f73421a4eb957e2413 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -8,6 +8,7 @@ packages = \
 ['knot_resolver',
  'knot_resolver.client',
  'knot_resolver.config',
+ 'knot_resolver.config.templates',
  'knot_resolver.controller',
  'knot_resolver.manager',
  'knot_resolver.utils']