]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua: add distro-preconfig
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 15 Jan 2020 15:33:35 +0000 (16:33 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 21 Jan 2020 16:20:37 +0000 (17:20 +0100)
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

daemon/lua/distro-preconfig.lua.in [new file with mode: 0644]
daemon/lua/meson.build
meson.build
systemd/kresd@.service.in
systemd/meson.build

diff --git a/daemon/lua/distro-preconfig.lua.in b/daemon/lua/distro-preconfig.lua.in
new file mode 100644 (file)
index 0000000..56375a8
--- /dev/null
@@ -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
index f5697135b637512a3139e1854365b0456eb554bd..9991460c3d0f60d23e18cc02b5132e2d2aa72d20 100644 (file)
@@ -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
index 7e1b3cd7b6efbc8ab8ba2280c047b6441b88608f..4bd17aed14660061d4c580233ca49d50c8038767 100644 (file)
@@ -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) + '''
index 886e6da056989bdcf977d0aa82131413eca2a2bb..9b00770cce9564cf561b43f7612f7b5cacba2d4d 100644 (file)
@@ -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
index 549e5e4a6c34c22ee1ae95986d6c893c5ec73b96..b562b349e75c6a74ea90820cf34f96b7f6176044 100644 (file)
@@ -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