From: Tomas Krizek Date: Wed, 15 Jan 2020 15:33:35 +0000 (+0100) Subject: lua: add distro-preconfig X-Git-Tag: v5.0.0~3^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d240698ee97c67213f538cb7cbce916a88b2258;p=thirdparty%2Fknot-resolver.git lua: add distro-preconfig The preconfig is used to set distro-specific values to avoid messing with user config, in partciular: - binding to control sockets under systemd - setting default cache location --- diff --git a/daemon/lua/distro-preconfig.lua.in b/daemon/lua/distro-preconfig.lua.in new file mode 100644 index 000000000..56375a86f --- /dev/null +++ b/daemon/lua/distro-preconfig.lua.in @@ -0,0 +1,15 @@ +local id = os.getenv('SYSTEMD_INSTANCE') + +if not id then + error('environment variable $SYSTEMD_INSTANCE not set') +else + -- Bind to control socket in run_dir + local path = '@run_dir@/control/'..id + local ok, err = pcall(net.listen, path, nil, { kind = 'control' }) + if not ok then + error('bind to '..path..' failed '..err) + end + + -- Set cache location + rawset(cache, 'current_storage', 'lmdb://@systemd_cache_dir@') +end diff --git a/daemon/lua/meson.build b/daemon/lua/meson.build index f5697135b..9991460c3 100644 --- a/daemon/lua/meson.build +++ b/daemon/lua/meson.build @@ -8,6 +8,8 @@ config_tests += [ lua_config = configuration_data() lua_config.set('keyfile_default', keyfile_default) lua_config.set('etc_dir', etc_dir) +lua_config.set('run_dir', run_dir) +lua_config.set('systemd_cache_dir', systemd_cache_dir) lua_config.set('unmanaged', managed_ta ? 'false' : 'true') trust_anchors = configure_file( @@ -22,6 +24,12 @@ sandbox = configure_file( configuration: lua_config, ) +distro_preconfig = configure_file( + input: 'distro-preconfig.lua.in', + output: 'distro-preconfig.lua', + configuration: lua_config, +) + run_target( # run manually to re-generate kres-gen.lua 'kres-gen', command: find_program('./kres-gen.sh'), @@ -35,6 +43,7 @@ lua_src = [ trust_anchors, files('zonefile.lua'), files('kluautil.lua'), + distro_preconfig, ] # install daemon lua sources diff --git a/meson.build b/meson.build index 7e1b3cd7b..4bd17aed1 100644 --- a/meson.build +++ b/meson.build @@ -50,10 +50,11 @@ etc_dir = join_paths(prefix, get_option('sysconfdir'), 'knot-resolver') lib_dir = join_paths(prefix, get_option('libdir'), 'knot-resolver') modules_dir = join_paths(lib_dir, 'kres_modules') sbin_dir = join_paths(prefix, get_option('sbindir')) -systemd_work_dir = '' -run_dir = '' -systemd_unit_dir = '' -systemd_tmpfiles_dir = '' +run_dir = join_paths('/run', 'knot-resolver') +systemd_work_dir = join_paths(prefix, get_option('localstatedir'), 'lib', 'knot-resolver') +systemd_cache_dir = join_paths(prefix, get_option('localstatedir'), 'cache', 'knot-resolver') +systemd_unit_dir = join_paths(prefix, 'lib', 'systemd', 'system') +systemd_tmpfiles_dir = join_paths(prefix, 'lib', 'tmpfiles.d') mod_inc_dir = include_directories('.', 'contrib/') ## Trust anchors @@ -281,6 +282,7 @@ message(''' systemd: files: @0@'''.format(systemd_files) + ''' work_dir: @0@'''.format(systemd_work_dir) + ''' + cache_dir: @0@'''.format(systemd_cache_dir) + ''' optional components client: @0@'''.format(s_build_client) + ''' diff --git a/systemd/kresd@.service.in b/systemd/kresd@.service.in index 886e6da05..9b00770cc 100644 --- a/systemd/kresd@.service.in +++ b/systemd/kresd@.service.in @@ -11,7 +11,7 @@ After=network-online.target Type=notify Environment="SYSTEMD_INSTANCE=%i" WorkingDirectory=@systemd_work_dir@ -ExecStart=@sbin_dir@/kresd --config=@etc_dir@/kresd.conf --noninteractive +ExecStart=@sbin_dir@/kresd -c @lib_dir@/distro-preconfig.lua -c @etc_dir@/kresd.conf -n User=@user@ Group=@group@ CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SETPCAP diff --git a/systemd/meson.build b/systemd/meson.build index 549e5e4a6..b562b349e 100644 --- a/systemd/meson.build +++ b/systemd/meson.build @@ -1,11 +1,5 @@ # systemd -## paths -systemd_work_dir = join_paths( - prefix, get_option('localstatedir'), 'cache', 'knot-resolver') -systemd_unit_dir = join_paths(prefix, 'lib', 'systemd', 'system') -systemd_tmpfiles_dir = join_paths(prefix, 'lib', 'tmpfiles.d') - ## configuration systemd_config = configuration_data() systemd_config.set('user', user) @@ -14,6 +8,7 @@ systemd_config.set('systemd_work_dir', systemd_work_dir) systemd_config.set('sbin_dir', sbin_dir) systemd_config.set('etc_dir', etc_dir) systemd_config.set('run_dir', run_dir) +systemd_config.set('lib_dir', lib_dir) if systemd_files == 'enabled' ## unit files