conf: settle the block format's key names and value shapes

The initial implementation was done using a naive translator of the
legacy one-liner format key by key, so it inherited encodings that the
block format exists to remove: a timeout packed into a script path, a
small comma-and-colon language inside the log string, sigils standing in
for booleans, and a log key (services) carrying three (!) types.

Settled naming against systemd, OpenRC, FreeBSD rc.subr, s6 and SMF.
Match systemd's semantics, not its naming.

    pid          -> pidfile, plus pidfile-create for the rare case
                    where Finit writes the file rather than the daemon
    environment  -> envfile, since it names a file to source, and the
                    top-level environment {} block sets variables
    pre/post/... -> exec-start-pre, exec-start-ready, exec-stop,
                    exec-stop-post, exec-reload, exec-cleanup, each
                    with its own -timeout instead of "SEC,script"
    halt, kill   -> stop-signal, stop-timeout
    restart      -> restart for the policy, restart-max for the count
    log          -> a block with file, priority and identity, where
                    /dev/null and /dev/console are spelled as paths
    group        -> group and extra-groups, no longer positional
    nowarn       -> a leading - on command, as on envfile

List-valued keys take plural names.  Aliases are desc, cond, mod,
caps, env, halt and kill; an alias may abbreviate the canonical name
or preserve a legacy spelling, nothing else.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-07-30 15:21:28 +02:00
1 parent 8a3d55b416
commit 8a541acd36
3 files changed
+276 -84

No files matched your search

+54 -3
View File
@@ -23,7 +23,7 @@ run envprobe {\n\
test_teardown()
{
say "Running test teardown."
run "rm -f $FINIT_CONF /tmp/envprobe-*"
run "rm -f $FINIT_CONF /tmp/envprobe-* /tmp/pre /run/blockfmt.pid /run/notmine.pid"
run "rm -f $FINIT_RCSD/legacy-side.conf"
}
@@ -65,8 +65,8 @@ say "Add new-format service block in $FINIT_CONF"
run "echo 'service service.sh {' > $FINIT_CONF"
run "echo ' description = \"Test service\"' >> $FINIT_CONF"
run "echo ' runlevel = \"2345\"' >> $FINIT_CONF"
run "echo ' kill = 20' >> $FINIT_CONF"
run "echo ' log = true' >> $FINIT_CONF"
run "echo ' stop-timeout = 20' >> $FINIT_CONF"
run "echo ' log { }' >> $FINIT_CONF"
# Exercises the cgroup translation path. Whether the group is really
# joined cannot be asserted here, cgroup_avail() is false inside the
# test namespace, so initctl reports no cgroup at all.
@@ -131,3 +131,54 @@ run "initctl reload"
retry 'assert_num_children 1 service.sh'
assert_desc "Test service" service.sh
# The renamed and split settings each have translation logic behind
# them, so exercise the ones with a visible effect.
# Only the warning differs, service_register() bails before svc_new()
# either way, so this asserts the stanza is skipped, not that the
# warning was suppressed. The emitted one-liner is where nowarn is
# visible, with finit.debug=on.
say 'A leading - on command tolerates a missing binary'
run "echo 'service ghost {' > $FINIT_CONF"
run "echo ' description = \"Ghost\"' >> $FINIT_CONF"
run "echo ' command = \"-/no/such/binary\"' >> $FINIT_CONF"
run "echo '}' >> $FINIT_CONF"
run "initctl reload"
assert_num_services 0 ghost
say 'exec-start-pre runs before the service, pidfile-create makes Finit own the file'
run "echo 'service service.sh {' > $FINIT_CONF"
run "echo ' description = \"Test service\"' >> $FINIT_CONF"
run "echo ' conditions = { \"hook/svc/up\" }' >> $FINIT_CONF"
run "echo ' exec-start-pre = \"/bin/pre.sh\"' >> $FINIT_CONF"
run "echo ' exec-start-pre-timeout = 5' >> $FINIT_CONF"
run "echo ' pidfile = \"/run/blockfmt.pid\"' >> $FINIT_CONF"
run "echo ' pidfile-create = true' >> $FINIT_CONF"
run "echo ' restart = true' >> $FINIT_CONF"
run "echo ' restart-max = 3' >> $FINIT_CONF"
run "echo ' command = \"service.sh\"' >> $FINIT_CONF"
run "echo '}' >> $FINIT_CONF"
run "initctl reload"
retry 'assert_num_children 1 service.sh'
retry 'assert_file_exists /tmp/pre'
assert_restart_cnt 0 "0/3" service.sh
# service.sh writes /run/service.pid, never /run/blockfmt.pid, so only
# Finit can have created this one. assert_is_pidfile cannot tell, it
# prints the path with any leading ! stripped.
retry 'assert_file_exists /run/blockfmt.pid'
say 'Without pidfile-create the daemon owns the file, Finit does not make it'
run "echo 'service service.sh {' > $FINIT_CONF"
run "echo ' description = \"Test service\"' >> $FINIT_CONF"
run "echo ' pidfile = \"/run/notmine.pid\"' >> $FINIT_CONF"
run "echo ' command = \"service.sh\"' >> $FINIT_CONF"
run "echo '}' >> $FINIT_CONF"
run "rm -f /run/notmine.pid"
run "initctl reload"
retry 'assert_num_children 1 service.sh'
assert "daemon-owned pidfile is not created by Finit" \
"$(texec ls /run/notmine.pid 2>/dev/null)" = ""
+1 -1
View File
@@ -25,7 +25,7 @@ test_teardown()
say 'Install a block-format template'
run "echo 'service serv:%i {' > $FINIT_RCSD/available/serv@.conf"
run "echo ' description = \"Template for %i\"' >> $FINIT_RCSD/available/serv@.conf"
run "echo ' pid = \"/run/serv-%i.pid\"' >> $FINIT_RCSD/available/serv@.conf"
run "echo ' pidfile = \"/run/serv-%i.pid\"' >> $FINIT_RCSD/available/serv@.conf"
run "echo ' command = \"serv -n -p -P /run/serv-%i.pid\"' >> $FINIT_RCSD/available/serv@.conf"
run "echo '}' >> $FINIT_RCSD/available/serv@.conf"