initctl: add the settings of a service to the JSON status

initctl -j status had the state of a service but little of how it is
set up.  A program reading it could not tell how the service is
stopped, what scripts it runs, or how it signals readiness.

Add the settings: stop, reload, notify, remain, scripts, directories,
cgroup-config, rlimits, log or tty, provides, conflicts, if, groups,
capabilities, pam, name, id, protected, and nowarn.  The restart
object also gets sec, respawn, and oncrash, and the state Finit keeps
for its own use goes in internal:

    "stop": {
      "signal": "SIGTERM",
      "timeout": 3,
      "scope": "pgroup"
    },
    "scripts": {
      "exec-stop-post": { "command": "/bin/true", "timeout": 7 }
    },

initctl reads the status over D-Bus first, so each setting is also a
property of org.finit.Service1.  The new test checks that the JSON is
the same over D-Bus as over the initctl socket.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-19 21:51:23 +01:00
1 parent 9fa50746a7
commit c94fd9c495
12 files changed
+893 -29

No files matched your search

+2
View File
@@ -73,6 +73,7 @@ EXTRA_DIST += run-task-tricks.sh
EXTRA_DIST += runparts.sh
EXTRA_DIST += sysvparts.sh
EXTRA_DIST += start-stop-service.sh
EXTRA_DIST += status-json.sh
EXTRA_DIST += start-stop-service-sub-config.sh
EXTRA_DIST += start-kill-service.sh
EXTRA_DIST += start-kill-stop.sh
@@ -148,6 +149,7 @@ TESTS += run-restart-forever.sh
TESTS += run-task-tricks.sh
TESTS += runparts.sh
TESTS += start-stop-service.sh
TESTS += status-json.sh
TESTS += start-stop-service-sub-config.sh
TESTS += start-kill-service.sh
TESTS += start-kill-stop.sh
+1 -1
View File
@@ -78,7 +78,7 @@ assert_delay 4 5 4 5
say 'The restart counter stops where the delay peaks'
assert "Delay and limit in status" "$(texec initctl status crash | sed -n 's/.*Restart in : //p')" = "4 sec (max 4)"
run "initctl -j status crash"
assert "Same in JSON" "$(texec initctl -j status crash | jq -c .restart)" = '{"count":2,"max":-1,"delay":4,"limit":4}'
assert "Same in JSON" "$(texec initctl -j status crash | jq -c .restart)" = '{"count":2,"max":-1,"sec":1,"delay":4,"limit":4,"respawn":false,"oncrash":"ignore"}'
assert "Restart counter is 2" "$(texec initctl status crash | awk '/Restarts/{ print $4 }')" = "(2/-1)"
sep
+98
View File
@@ -0,0 +1,98 @@
#!/bin/sh
# Verify initctl -j status: it has the settings of a service, and gives
# the same over D-Bus as over the initctl socket.
set -eu
TEST_DIR=$(dirname "$0")
BUS=/run/finit/bus
# Check member $1 of the JSON status in $json
assert_json()
{
assert "$1 is $2" "$(echo "$json" | jq -c "$1")" = "$2"
}
test_teardown()
{
say "Running test teardown."
run "test -e $BUS.hidden && mv $BUS.hidden $BUS || true"
run "rm -f $FINIT_CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "cat > $FINIT_CONF" <<CONF
service json {
description = "JSON status"
notify = "pid"
stop-signal = "SIGINT"
stop-timeout = 5
stop-scope = "process"
restart-max = 3
restart-sec = 2
restart-max-sec = 8
oncrash = "script"
exec-stop-post = "/bin/true"
exec-stop-post-timeout = 7
runtime-dir = "json"
runtime-dir-mode = 0750
rlimit {
soft.nofile = 123
hard.nofile = 456
core = unlimited
}
cgroup maint { cpu.weight = 250 }
runtime-dir-preserve = "restart"
extra-groups = { "daemon", "bin" }
provides = { "usr/json-a", "usr/json-b" }
conflicts = { "nosuch" }
log {
identity = "jason"
}
command = "serv -np -i json"
}
CONF
run "initctl reload"
retry 'assert_status json running'
sep
say 'The settings of the service are in the JSON status'
run "initctl -j status json"
json=$(texec initctl -j status json)
assert_json .notify '"pid"'
assert_json .remain 'false'
assert_json .stop '{"signal":"SIGINT","timeout":5,"scope":"process"}'
assert_json .reload.signal '"SIGHUP"'
assert_json .restart.max '3'
assert_json .restart.sec '2'
assert_json .restart.limit '8'
assert_json .restart.respawn 'false'
assert_json .restart.oncrash '"script"'
assert_json .scripts '{"exec-stop-post":{"command":"/bin/true","timeout":7}}'
assert_json .directories '{"runtime":{"name":"json","mode":"0750"},"preserve":"restart"}'
assert_json .rlimits.nofile '{"soft":123,"hard":456}'
assert_json .rlimits.core '{"soft":"unlimited","hard":"unlimited"}'
assert_json '."cgroup-config"' '{"group":"maint","config":"cpu.weight:250","delegate":false}'
assert_json .name '"json"'
assert_json .protected 'false'
assert_json .id '""'
assert_json .internal.removed 'false'
assert_json .internal.oldpid '0'
assert_json .reload.propagate 'false'
assert_json .groups '["daemon","bin"]'
assert_json .provides '["usr/json-a","usr/json-b"]'
assert_json .conflicts '["nosuch"]'
assert_json .log.enabled 'true'
assert_json .log.identity '"jason"'
if texec test -e $BUS; then
sep
say 'Same over the initctl socket, with the bus hidden'
run "mv $BUS $BUS.hidden"
legacy=$(texec initctl -j status json)
run "mv $BUS.hidden $BUS"
assert "Same JSON from both" "$(echo "$json" | jq -cS 'del(.uptime)')" = "$(echo "$legacy" | jq -cS 'del(.uptime)')"
fi