NAME

Configd::Unit - The systemd drop-in that rebuilds a language's files before the daemon reads them.

VERSION

version 0.002

SYNOPSIS

use Configd();
use Configd::Unit();

my $postfix = Configd->language('postfix');
my $unit    = Configd::Unit->new( language => $postfix, configd => '/usr/bin/configd' );

my @written = $unit->install();
my $wrapped = $unit->installed();

DESCRIPTION

A generated file is only true until somebody edits it, and the file Configd generates is the one every piece of documentation on the internet tells people to edit. Rather than trying to stop that, Configd regenerates the file at the moment it matters: a systemd drop-in on the units the language names, running configd build before the daemon starts and again before it is told to reload.

The daemon therefore always reads what the fragments say, and an edit to the generated file survives exactly until the next restart -- which is long enough to test something and short enough that nobody comes to rely on it.

Why a drop-in rather than a unit of our own

Replacing the packaged unit means owning it: every upgrade that changes it is a conflict to resolve, and a distribution that reworks how the service starts breaks a copy that was accurate when it was made. A drop-in in /etc/systemd/system/<unit>.d/ adds to whatever the package ships and keeps working across an upgrade that rewrites it.

Ordering

ExecStartPre lines in a drop-in are appended to the ones the packaged unit already has, so ours runs after the package's own pre-start work and still before ExecStart. That is the order we want: the package's script sets an instance up, and we write the config the daemon is about to read.

Prepending would mean clearing the list with an empty ExecStartPre= and restating every line the package shipped, which is precisely the copy that goes stale on upgrade.

Why the commands begin with +

A hardened unit runs ExecStartPre under everything it applies to the daemon itself, and a modern packaged unit applies a great deal. Ubuntu 24.04's redis-server.service is the example that taught us:

User=redis
NoExecPaths=/
ExecPaths=/usr/bin/redis-server /usr/lib /lib
SystemCallFilter=~@privileged

Under that, /usr/bin/configd is not an executable path at all -- systemd answers status=203/EXEC and, after five tries, leaves redis failed. Get past that and the process is the redis user with @privileged syscalls filtered, so writing into /etc and putting the file's ownership back are SIGSYS rather than EPERM: the helper is killed and core-dumped mid-write.

The + prefix runs the command with full privileges, outside User=, the namespace restrictions and the seccomp filter. Regenerating a config file is exactly the kind of setup step it exists for, and without it adopting a hardened service takes that service down.

NAME

Configd::Unit - the systemd drop-in that rebuilds a language's files before the daemon reads them.

METHODS

$class->new(%opts)

  • language -- the Configd::Language whose units these are. Required.

  • configd -- the path to the configd executable as the unit will invoke it. Defaults to /usr/bin/configd; systemd needs it absolute.

  • root -- write under here rather than /, for tests. Taken from the language when not given.

$unit->dropin_dir($unit_name)

Where a unit's drop-ins live.

$unit->render()

The drop-in's text.

$unit->install()

Write the drop-in for every unit the language names, returning the paths written.

$unit->uninstall()

Take the drop-in back off every unit, returning the paths removed.

The generated files are left where they are, because the service is running on them. Configd::Language::release is what puts the originals back.

$unit->installed()

Whether every unit this language names currently has the drop-in.

SEE ALSO

Please see those modules/websites for more information related to this module.

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/teodesian/perl-configd/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHORS

Current Maintainers:

  • George S. Baugh <george@troglodyne.net>

COPYRIGHT AND LICENSE

Copyright (c) 2026 Troglodyne LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.