From: Tomas Krizek Date: Fri, 8 Feb 2019 11:42:18 +0000 (+0100) Subject: meson: systemd - configure and install X-Git-Tag: v4.0.0~24^2~162 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=295cd2ea05e9990b98a463716a814d2bb2162e2c;p=thirdparty%2Fknot-resolver.git meson: systemd - configure and install --- diff --git a/distro/common/systemd/README.md b/distro/common/systemd/README.md deleted file mode 100644 index 433f92fb0..000000000 --- a/distro/common/systemd/README.md +++ /dev/null @@ -1,31 +0,0 @@ -Running Knot Resolver under systemd (or equivalent) socket activation -===================================================================== - -You can use the files in this directory to run kresd under supervision -by systemd (or any supervisor that provides equivalent file descriptor -initialization via the interface supported by -sd_listen_fds_with_names(3)). - -Usage and Configuration ------------------------ - -See kresd.systemd(7) for details. - -Compatibility with older systemd --------------------------------- - -If you're using systemd prior to version 227, use the systemd-compat.conf -drop-in file to use manual activation. In this case, socket files shouldn't -be packaged, because they won't be used. - -Notes ------ - -* If you're using the upstream systemd unit files, don't forget to also include - kresd.systemd.7 manual page in the package. -* Distributions using systemd-sysv-generator should mask kresd.service to - be consistent with other distributions. Any use of kresd.service instead of - kresd@N.service is discouraged to avoid confusing the users. -* kresd.target should be enabled by default by linking it to systemd lib/ - directory. Instances of kresd@.service are then added manually to - kresd.target when the user enables them. diff --git a/distro/common/systemd/drop-in/listen-tls.conf b/distro/common/systemd/drop-in/listen-tls.conf deleted file mode 100644 index 6c798f0c9..000000000 --- a/distro/common/systemd/drop-in/listen-tls.conf +++ /dev/null @@ -1,7 +0,0 @@ -# /etc/systemd/system/kresd-tls.socket.d/override.conf - -# Configure which interfaces should kresd listen on. -# ListenStream can be added multiple times. - -[Socket] -ListenStream=192.0.2.115:853 diff --git a/distro/common/systemd/drop-in/listen-udp-tcp.conf b/distro/common/systemd/drop-in/listen-udp-tcp.conf deleted file mode 100644 index 480767abb..000000000 --- a/distro/common/systemd/drop-in/listen-udp-tcp.conf +++ /dev/null @@ -1,8 +0,0 @@ -# /etc/systemd/system/kresd.socket.d/override.conf - -# Configure which interfaces should kresd listen on. -# ListenDatagram and ListenStream can be added multiple times. - -[Socket] -ListenDatagram=192.0.2.115:53 -ListenStream=192.0.2.115:53 diff --git a/distro/common/systemd/drop-in/systemd-compat.conf b/distro/common/systemd/drop-in/systemd-compat.conf deleted file mode 100644 index d251c4152..000000000 --- a/distro/common/systemd/drop-in/systemd-compat.conf +++ /dev/null @@ -1,17 +0,0 @@ -# /usr/lib/systemd/system/kresd@.service.d/override.conf - -# If systemd.227+ isn't available (e.g. CentOS 7), socket activation can't be used -# and the following modifications are required to use the service with -# manual activation. - -# CAP_NET_BIND_SERVICE is necessary to be able to bind to a well-known port -# as an unprivilidged user. - -# Explicit --forks=1 turns off interactive mode. - -[Service] -Type=simple -AmbientCapabilities=CAP_NET_BIND_SERVICE -ExecStart= -ExecStart=/usr/sbin/kresd --config=/etc/knot-resolver/kresd.conf --forks=1 -Sockets= diff --git a/distro/common/tmpfiles/knot-resolver.conf b/distro/common/tmpfiles/knot-resolver.conf deleted file mode 100644 index 9ac595273..000000000 --- a/distro/common/tmpfiles/knot-resolver.conf +++ /dev/null @@ -1,4 +0,0 @@ -# tmpfiles.d(5) runtime directory for knot-resolver (kresd) -#Type Path Mode UID GID Age Argument - d /run/knot-resolver 0750 root root - - - d /var/cache/knot-resolver 0750 knot-resolver knot-resolver - - diff --git a/meson.build b/meson.build index dbbc36c52..d1c656f26 100644 --- a/meson.build +++ b/meson.build @@ -36,6 +36,10 @@ data_dir = join_paths(prefix, get_option('datadir'), 'knot-resolver') doc_dir = join_paths(prefix, get_option('datadir'), 'doc', 'knot-resolver') etc_dir = join_paths(prefix, get_option('sysconfdir'), 'knot-resolver') sbin_dir = join_paths(prefix, get_option('sbindir')) +systemd_cache_dir = '' +run_dir = '' +systemd_unit_dir = '' +systemd_tmpfiles_dir = '' modules_dir = get_option('modules_dir') if modules_dir == '' @@ -152,6 +156,11 @@ subdir('tests') subdir('doc') subdir('etc') +# systemd integration +if systemd + subdir('systemd') +endif + # summary message # NOTE: ternary operator in format() not supported @@ -181,6 +190,8 @@ message(''' systemd: @0@'''.format(summary_systemd) + ''' socket activation: @0@'''.format(summary_systemd_socket) + ''' user mode: @0@'''.format(summary_systemd_user_mode) + ''' + cache_dir: @0@'''.format(systemd_cache_dir) + ''' + run_dir: @0@'''.format(run_dir) + ''' components client: @0@'''.format(summary_build_client) + ''' diff --git a/distro/common/systemd/kresd-control@.socket b/systemd/kresd-control@.socket.in similarity index 87% rename from distro/common/systemd/kresd-control@.socket rename to systemd/kresd-control@.socket.in index 6937436dc..2280f0840 100644 --- a/distro/common/systemd/kresd-control@.socket +++ b/systemd/kresd-control@.socket.in @@ -7,7 +7,7 @@ PartOf=kresd@%i.service [Socket] Service=kresd@%i.service -ListenStream=/run/knot-resolver/control@%i +ListenStream=@run_dir@/control@%i FileDescriptorName=control SocketMode=0660 Slice=system-kresd.slice diff --git a/distro/common/systemd/kresd-tls.socket b/systemd/kresd-tls.socket similarity index 100% rename from distro/common/systemd/kresd-tls.socket rename to systemd/kresd-tls.socket diff --git a/distro/common/systemd/kresd.socket b/systemd/kresd.socket similarity index 100% rename from distro/common/systemd/kresd.socket rename to systemd/kresd.socket diff --git a/distro/common/systemd/kresd.systemd.7 b/systemd/kresd.systemd.7 similarity index 100% rename from distro/common/systemd/kresd.systemd.7 rename to systemd/kresd.systemd.7 diff --git a/distro/common/systemd/kresd.target b/systemd/kresd.target similarity index 100% rename from distro/common/systemd/kresd.target rename to systemd/kresd.target diff --git a/distro/common/systemd/kresd@.service b/systemd/kresd@.service.in similarity index 66% rename from distro/common/systemd/kresd@.service rename to systemd/kresd@.service.in index 048aee01e..c559a611f 100644 --- a/distro/common/systemd/kresd@.service +++ b/systemd/kresd@.service.in @@ -5,9 +5,9 @@ Documentation=man:kresd(8) [Service] Type=notify -WorkingDirectory=/var/cache/knot-resolver -ExecStart=/usr/sbin/kresd --config=/etc/knot-resolver/kresd.conf -User=knot-resolver +WorkingDirectory=@systemd_cache_dir@ +ExecStart=@sbin_dir@/kresd --config=@etc_dir@/kresd.conf +User=@user@ Restart=on-failure Sockets=kresd.socket Sockets=kresd-tls.socket diff --git a/systemd/meson.build b/systemd/meson.build new file mode 100644 index 000000000..0110675e4 --- /dev/null +++ b/systemd/meson.build @@ -0,0 +1,59 @@ +# systemd + +## paths +# TODO user mode +systemd_cache_dir = join_paths( + prefix, get_option('localstatedir'), 'cache', 'knot-resolver') +run_dir = join_paths('/run', 'knot-resolver') +systemd_unit_dir = join_paths(prefix, get_option('libdir'), 'systemd', 'system') +systemd_tmpfiles_dir = join_paths(prefix, get_option('libdir'), 'tmpfiles.d') + +## configuration +systemd_config = configuration_data() +systemd_config.set('user', user) +systemd_config.set('group', group) +systemd_config.set('systemd_cache_dir', systemd_cache_dir) +systemd_config.set('sbin_dir', sbin_dir) +systemd_config.set('etc_dir', etc_dir) +systemd_config.set('run_dir', run_dir) + +# TODO Restart=on-abnormal + +if systemd_socket + # unit files + kresd_service = configure_file( + input: 'kresd@.service.in', + output: 'kresd@.service', + configuration: systemd_config, + install_dir: systemd_unit_dir, + ) + kresd_control_socket = configure_file( + input: 'kresd-control@.socket.in', + output: 'kresd-control@.socket', + configuration: systemd_config, + install_dir: systemd_unit_dir, + ) + + install_data( + sources: [ + 'kresd.socket', + 'kresd-tls.socket', + 'kresd.target', + ], + install_dir: systemd_unit_dir, + ) + + install_man('kresd.systemd.7') # TODO amend man page + configure + + # tmpfiles + tmpfiles = configure_file( + input: 'tmpfiles.d/knot-resolver.conf.in', + output: 'knot-resolver.conf', + configuration: systemd_config, + install_dir: systemd_tmpfiles_dir, + ) + + # TODO example drop-ins +else + subdir('nosocket') +endif diff --git a/systemd/tmpfiles.d/knot-resolver.conf.in b/systemd/tmpfiles.d/knot-resolver.conf.in new file mode 100644 index 000000000..75237f599 --- /dev/null +++ b/systemd/tmpfiles.d/knot-resolver.conf.in @@ -0,0 +1,4 @@ +# tmpfiles.d(5) directories for knot-resolver (kresd) +#Type Path Mode UID GID Age Argument + d @run_dir@ 0750 root root - - + d @systemd_cache_dir@ 0750 @user@ @group@ - -