Commit 4b7d1211 authored by Marek Vavrusa's avatar Marek Vavrusa

daemon: systemd socket activation

addition to previous generic socket activation

fixes #11
parent d944e311
......@@ -26,6 +26,7 @@ $(eval $(call find_lib,libmemcached,1.0))
$(eval $(call find_lib,hiredis))
$(eval $(call find_lib,socket_wrapper))
$(eval $(call find_lib,libdnssec))
$(eval $(call find_lib,libsystemd))
$(eval $(call find_gopkg,geoip,github.com/abh/geoip))
# Find Go compiler version
# @note Go 1.5 support amd64 only, disabled for other architectures
......@@ -43,7 +44,7 @@ ifneq (,$(findstring luajit, $(lua_LIBS)))
endif
endif
BUILD_CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(cmocka_CFLAGS) $(lua_CFLAGS) $(libdnssec_CFLAGS)
BUILD_CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(cmocka_CFLAGS) $(lua_CFLAGS) $(libdnssec_CFLAGS) $(libsystemd_CFLAGS)
BUILD_CFLAGS += $(addprefix -I,$(wildcard contrib/ccan/*) contrib/murmurhash3)
# Overview
......@@ -78,6 +79,7 @@ info:
$(info [$(HAS_libmemcached)] libmemcached (modules/memcached))
$(info [$(HAS_hiredis)] hiredis (modules/redis))
$(info [$(HAS_cmocka)] cmocka (tests/unit))
$(info [$(HAS_libsystemd)] systemd (daemon))
$(info )
# Installation directories
......
......@@ -140,6 +140,8 @@ The watchdog process must notify kresd about active file descriptors, and kresd
[system] interactive mode
>
The daemon also supports [systemd socket activation](http://0pointer.de/blog/projects/socket-activation.html), it is automatically detected and requires no configuration on users's side.
Configuration
=============
......
......@@ -24,7 +24,14 @@ bindings-install: $(kresd_DIST) $(DESTDIR)$(MODULEDIR)
kresd_CFLAGS := -fPIE
kresd_DEPEND := $(libkres) $(contrib)
kresd_LIBS := $(libkres_TARGET) $(contrib_TARGET) $(libknot_LIBS) $(libzscanner_LIBS) $(libdnssec_LIBS) $(libuv_LIBS) $(lua_LIBS)
kresd_LIBS := $(libkres_TARGET) $(contrib_TARGET) $(libknot_LIBS) \
$(libzscanner_LIBS) $(libdnssec_LIBS) $(libuv_LIBS) $(lua_LIBS)
# Enable systemd
ifeq ($(HAS_libsystemd), yes)
kresd_CFLAGS += -DHAS_SYSTEMD
kresd_LIBS += $(libsystemd_LIBS)
endif
# Make binary
ifeq ($(HAS_lua)|$(HAS_libuv), yes|yes)
......
......@@ -23,6 +23,9 @@
#include <contrib/ucw/mempool.h>
#include <contrib/ccan/asprintf/asprintf.h>
#include <libknot/error.h>
#ifdef HAS_SYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include "lib/defines.h"
#include "lib/resolve.h"
......@@ -214,6 +217,10 @@ static int run_worker(uv_loop_t *loop, struct engine *engine)
uv_listen((uv_stream_t *) &pipe, 16, tty_accept);
}
}
/* Notify supervisor. */
#ifdef HAS_SYSTEMD
sd_notify(0, "READY=1");
#endif
/* Run event loop */
uv_run(loop, UV_RUN_DEFAULT);
if (sock_file) {
......@@ -319,6 +326,15 @@ int main(int argc, char **argv)
}
}
#ifdef HAS_SYSTEMD
/* Accept passed sockets from systemd supervisor. */
int sd_nsocks = sd_listen_fds(0);
for (int i = 0; i < sd_nsocks; ++i) {
int fd = SD_LISTEN_FDS_START + i;
array_push(fd_set, fd);
}
#endif
/* Switch to rundir. */
if (optind < argc) {
const char *rundir = argv[optind];
......
......@@ -48,6 +48,7 @@ There are also *optional* packages that enable specific functionality in Knot DN
"Doxygen_", "``documentation``", "Generating API documentation."
"Sphinx_", "``documentation``", "Building this HTML/PDF documentation."
"breathe_", "``documentation``", "Exposing Doxygen API doc to Sphinx."
"libsystemd_", "``daemon``", "Systemd socket activation support."
.. [#] Requires C99, ``__attribute__((cleanup))`` and ``-MMD -MP`` for dependency file generation. GCC, Clang and ICC are supported.
.. [#] You can use variables ``<dependency>_CFLAGS`` and ``<dependency>_LIBS`` to configure dependencies manually (i.e. ``libknot_CFLAGS`` and ``libknot_LIBS``).
......@@ -265,4 +266,6 @@ You can hack on the container by changing the container entrypoint to shell like
.. _deckard: https://gitlab.labs.nic.cz/knot/deckard
.. _deckard_doc: https://gitlab.labs.nic.cz/knot/resolver/blob/master/tests/README.rst
.. _libsystemd: https://www.freedesktop.org/wiki/Software/systemd/
.. _DESTDIR: https://www.gnu.org/prep/standards/html_node/DESTDIR.html
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment