etc/knot-resolver/config.yml
-lib/systemd/system/knot-resolver-manager.service
+lib/systemd/system/knot-resolver.service
DESTDIR="${PWD}/debian/tmp" ninja -v -C build_deb install
dh_auto_install --buildsystem=pybuild --sourcedirectory manager
install -m 644 -D $(CURDIR)/manager/etc/knot-resolver/config.yml $(CURDIR)/debian/tmp/etc/knot-resolver/config.yml
- install -m 644 -D $(CURDIR)/manager/knot-resolver-manager.service $(CURDIR)/debian/tmp/lib/systemd/system/knot-resolver-manager.service
+ install -m 644 -D $(CURDIR)/manager/knot-resolver.service $(CURDIR)/debian/tmp/lib/systemd/system/knot-resolver.service
override_dh_auto_test:
meson test -C build_deb
pushd manager
%py3_install
install -m 644 -D etc/knot-resolver/config.yml %{buildroot}%{_sysconfdir}/knot-resolver/config.yml
-install -m 644 -D knot-resolver-manager.service %{buildroot}%{_unitdir}/knot-resolver-manager.service
+install -m 644 -D knot-resolver.service %{buildroot}%{_unitdir}/knot-resolver.service
popd
%pre
%files -n python3-knot-resolver-manager
%{python3_sitelib}/knot_resolver_manager*
%{_sysconfdir}/knot-resolver/config.yml
-%{_unitdir}/knot-resolver-manager.service
+%{_unitdir}/knot-resolver.service
%changelog
* {{ now }} Jakub Ružička <jakub.ruzicka@nic.cz> - {{ version }}-{{ release }}
logging:
level: info
network:
- interfaces:
- - listen:
- ip: 127.0.0.1
- port: 53
+ listen:
+ - interface: 127.0.0.1@53
server:
- workers: 1
+ id: distro
+ workers: 2
+ rundir: /run/knot-resolver
management:
- listen:
- unix-socket: /run/knot-resolver/manager.sock
- rundir: /run/knot-resolver
+ unix-socket: /run/knot-resolver/manager.sock
After=dbus.service
[Service]
+Type=notify
ExecStart=python3 -m knot_resolver_manager --config=/etc/knot-resolver/config.yml
KillSignal=SIGINT
# See systemd.service(5) for explanation, why we should replace this with a blocking request
--- /dev/null
+def main():
+ print("Knot Resolver CLI successfully running...")
+ print("... unfortunatelly, it does nothing at the moment")
-def main():
- print("Knot Resolver CLI successfully running...")
- print("... unfortunatelly, it does nothing at the moment")
-
+from knot_resolver_manager.cli import main
if __name__ == "__main__":
main()
from knot_resolver_manager.exceptions import DataException, KresManagerException, SchemaException
from knot_resolver_manager.kresd_controller import get_controller_by_name
from knot_resolver_manager.kresd_controller.interface import SubprocessController
+from knot_resolver_manager.utils import systemd_notify
from knot_resolver_manager.utils.async_utils import readfile
from knot_resolver_manager.utils.functional import Result
from knot_resolver_manager.utils.parsing import ParsedTree, parse, parse_yaml
async def sighup_handler(self) -> None:
logger.info("Received SIGHUP, reloading configuration file")
+ systemd_notify.systemd_notify(RELOADING="1")
+
if self._config_path is None:
logger.warning("The manager was started with inlined configuration - can't reload")
else:
logger.error(f"Reloading of the configuration file failed: {e}")
logger.error("Configuration have NOT been changed.")
+ systemd_notify.systemd_notify(READY="1")
+
@staticmethod
def all_handled_signals() -> Set[signal.Signals]:
return {signal.SIGHUP, signal.SIGINT, signal.SIGTERM}
logger.info(f"Manager fully initialized and running in {round(time() - start_time, 3)} seconds")
+ # notify systemd about that we are ready
+ systemd_notify.systemd_notify(READY="1")
+
await server.wait_for_shutdown()
+ # notify systemd that we are shutting down
+ systemd_notify.systemd_notify(STOPPING="1")
+
# Ok, now we are tearing everything down.
# First of all, let's block all unwanted interruptions. We don't want to be reconfiguring kresd's while
--- /dev/null
+import enum
+import logging
+import os
+import socket
+
+
+logger = logging.getLogger(__name__)
+
+
+class _Status(enum.Enum):
+ NOT_INITIALIZED = 1
+ FUNCTIONAL = 2
+ FAILED = 3
+
+
+_status = _Status.NOT_INITIALIZED
+_socket = None
+
+
+def systemd_notify(**values: str) -> None:
+ global _status
+ global _socket
+
+ if _status is _Status.NOT_INITIALIZED:
+ socket_addr = os.getenv("NOTIFY_SOCKET")
+ os.unsetenv("NOTIFY_SOCKET")
+ if socket_addr is None:
+ _status = _Status.FAILED
+ return
+ if socket_addr.startswith("@"):
+ socket_addr = socket_addr.replace("@", "\0", 1)
+
+ try:
+ _socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ _socket.connect(socket_addr)
+ _status = _Status.FUNCTIONAL
+ except Exception:
+ _socket = None
+ _status = _Status.FAILED
+ logger.warning(f"Failed to connect to $NOTIFY_SOCKET at '{socket_addr}'", exc_info=True)
+ return
+
+ elif _status is _Status.FAILED:
+ return
+
+ if _status is _Status.FUNCTIONAL:
+ assert _socket is not None
+ payload = "\n".join((f"{key}={value}" for key, value in values.items()))
+ try:
+ _socket.send(payload.encode("utf8"))
+ except Exception:
+ logger.warning("Failed to send notification to systemd", exc_info=True)
+ _status = _Status.FAILED
+ _socket.close()
+ _socket = None
python3 -m pipx install apkg
# prepare the repo
-git clone https://gitlab.nic.cz/knot/knot-resolver
-cd knot-resolver
+#git clone https://gitlab.nic.cz/knot/knot-resolver
+cd /repo
git config --global user.email "automated-script"
git config --global user.name "Automated Script"
git checkout manager-integration-without-submodule
systemctl start knot-resolver.service
-# FIXME remove after implementing sd_notify in manager
-sleep 10
-
# check that the resolvers are actually running
kdig @127.0.0.1 nic.cz
\ No newline at end of file