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

+6 -1
View File
@@ -18,7 +18,12 @@ All relevant changes are documented in this file.
service. New is a `restart` object with the restart counter,
`restart-max`, the current restart delay and its limit, and `manual`
and `started`. `starts` is now there for all services, not only those
with `manual-start`
with `manual-start`. Also new are the settings of the service: `stop`,
`reload`, `notify`, `remain`, `scripts`, `directories`, `log` or `tty`,
`cgroup-config`, `rlimits`, `provides`, `conflicts`, `if`, `groups`,
`capabilities`, `pam`, `name`, `id`, `protected`, `nowarn`, and the
state Finit keeps for its own use in `internal`, see
[Commands & Status](initctl.md), with a D-Bus property for each
- Add `restart-max-sec`, a limit for the delay between restarts of a
crashing service. When set, the delay doubles for each restart, from
`restart-sec` up to the limit, and comes down again as the service keeps
+65
View File
@@ -193,6 +193,71 @@ All read-only; observable via `Properties.Get` and `Properties.GetAll`.
| `ManualStart` | `b` | `manual-start` set in the `.conf` |
| `Forking` | `b` | Daemon forks to background |
| `Started` | `b` | Run/task completed successfully |
| `Notify` | `s` | Readiness protocol: `none`, `pid`, `systemd`, or `s6` |
| `Remain` | `b` | `remain-after-exit` set in the `.conf` |
| `If` | `s` | The `if` setting, raw |
| `Provides` | `s` | Conditions from `provides`, comma separated |
| `Conflicts` | `s` | Services from `conflicts`, comma separated |
| `ExtraGroups` | `s` | Supplementary groups, comma separated |
| `Capabilities` | `s` | The `capabilities` setting, comma separated |
| `Pam` | `s` | PAM service name, empty when not set |
| `StopSignal` | `s` | Signal that stops the service, e.g. `SIGTERM` |
| `StopTimeout` | `u` | Seconds to wait for it to stop, before `SIGKILL` |
| `StopScope` | `s` | `pgroup`, `process`, `cgroup`, or `mixed` |
| `ReloadSignal` | `s` | `SIGHUP`, or `none` when a reload restarts the service |
| `RestartSec` | `u` | The `restart-sec` setting, 0 when not set |
| `Respawn` | `b` | `respawn` set in the `.conf` |
| `OnCrash` | `s` | `ignore`, `reboot`, or `script` |
| `RuntimeDir` | `s` | The `runtime-dir` setting, likewise for the four below |
| `StateDir` | `s` | |
| `CacheDir` | `s` | |
| `LogsDir` | `s` | |
| `ConfigDir` | `s` | |
| `RuntimeDirPreserve` | `s` | `no`, `restart`, or `yes` |
| `RuntimeDirMode` | `u` | Mode of the runtime directory, likewise for the four below |
| `StateDirMode` | `u` | |
| `CacheDirMode` | `u` | |
| `LogsDirMode` | `u` | |
| `ConfigDirMode` | `u` | |
| `Id` | `s` | The `:ID` part of the identity, empty when there is none |
| `Job` | `u` | Job number, internal |
| `OldPid` | `u` | PID of the previous run, internal |
| `Dirty` | `b` | Changed in the `.conf`, pending the next reload, internal |
| `Removed` | `b` | Gone from the `.conf`, pending removal, internal |
| `Starting` | `b` | Started, waiting for its PID file or readiness, internal |
| `Protected` | `b` | Built-in service, kept when the configuration is reloaded |
| `NoWarn` | `b` | No warning when the command is missing |
| `ReloadPropagate` | `b` | A reload of a dependency reloads this service too, `~` in its conditions |
| `CgroupName` | `s` | Control group the service joins, empty for the default |
| `CgroupConfig` | `s` | Its cgroup settings, `key:value` comma separated |
| `CgroupDelegate` | `b` | The service manages its own cgroup subtree |
| `Rlimits` | `s` | Resource limits as `name=soft:hard`, comma separated, a number or `unlimited` |
| `ExecStartPre` | `s` | Script, empty when not set, likewise for the five below |
| `ExecStartPreTimeout` | `u` | Seconds the script may run, one for each script |
| `ExecStartReady` | `s` | |
| `ExecStartReadyTimeout` | `u` | |
| `ExecStop` | `s` | |
| `ExecStopTimeout` | `u` | |
| `ExecStopPost` | `s` | |
| `ExecStopPostTimeout` | `u` | |
| `ExecReload` | `s` | |
| `ExecReloadTimeout` | `u` | |
| `ExecCleanup` | `s` | |
| `ExecCleanupTimeout` | `u` | |
| `Log` | `b` | Output is logged, not for a `tty` |
| `LogNull` | `b` | Output is discarded |
| `LogConsole` | `b` | Output goes to the console |
| `LogFile` | `s` | Log file, empty for syslog |
| `LogPriority` | `s` | Syslog facility and level, empty for the default |
| `LogIdentity` | `s` | Syslog identity, empty for the default |
| `TtyDevice` | `s` | Device of a `tty`, this and the below are empty or false for other types |
| `TtyBaud` | `s` | Baud rate, empty for the default |
| `TtyTerm` | `s` | The `TERM` to set |
| `TtyNoClear` | `b` | `noclear` set in the `.conf` |
| `TtyNoWait` | `b` | `nowait` set in the `.conf` |
| `TtyNoLogin` | `b` | `nologin` set in the `.conf` |
| `TtyNoTty` | `b` | `notty` set in the `.conf` |
| `TtyRescue` | `b` | `rescue` set in the `.conf` |
On every state transition the object also emits the standard
`org.freedesktop.DBus.Properties.PropertiesChanged` signal: `State`
+71 -7
View File
@@ -147,8 +147,8 @@ Apr 8 15:02:12 alpine authpriv.notice dropbear[2634]: Password auth succeeded f
```
With `-j` the same command gives JSON, for scripts and other programs.
The view above is kept short for reading, the JSON has everything
`initctl` gets from Finit about the service:
The view above is kept short for reading, the JSON also has the
settings of the service:
```
alpine:~# initctl -j status dialer
@@ -168,8 +168,58 @@ alpine:~# initctl -j status dialer
"restart": {
"count": 4,
"max": -1,
"sec": 10,
"delay": 160,
"limit": 300
"limit": 300,
"respawn": false,
"oncrash": "ignore"
},
"name": "dialer",
"id": "",
"internal": {
"job": 12,
"oldpid": 1234,
"starting": false,
"dirty": false,
"removed": false
},
"protected": false,
"nowarn": false,
"notify": "none",
"remain": false,
"stop": {
"signal": "SIGTERM",
"timeout": 3,
"scope": "pgroup"
},
"reload": {
"signal": "SIGHUP",
"propagate": false
},
"scripts": {
"exec-stop-post": { "command": "/usr/libexec/dialer-down", "timeout": 3 }
},
"directories": {
"runtime": { "name": "dialer", "mode": "0755" },
"preserve": "no"
},
"cgroup-config": {
"group": "",
"config": "",
"delegate": false
},
"rlimits": {
"core": { "soft": 0, "hard": "unlimited" },
"nofile": { "soft": 1024, "hard": 4096 },
...
},
"log": {
"enabled": true,
"null": false,
"console": false,
"file": "",
"priority": "",
"identity": "dialer"
},
"pidfile": "none",
"pid": 0,
@@ -183,10 +233,24 @@ alpine:~# initctl -j status dialer
In `restart`, `count` is the restart counter that `restart-max`, here
`max`, is compared to, -1 for `restart = "always"`. The total since
boot is in `restarts`. `delay` is the number of seconds before the
next restart, should the service crash, and `limit` is its
`restart-max-sec`, 0 when not set. `environment`, `condition`, `exit`,
and the cgroup members `cgroup`, `memory`, `cpu`, and `limits` are left
out when they do not apply.
next restart, should the service crash, `sec` is `restart-sec`, and
`limit` is `restart-max-sec`, both 0 when not set. All times are in
seconds.
The settings use the names from the [configuration](config/service-opts.md):
`scripts` has the `exec-*` scripts that are set, each with its timeout,
`directories` the `runtime`, `state`, `cache`, `logs`, and `config`
directories that are set, and `preserve`. `cgroup-config` is the
`cgroup` setting of the service, where `cgroup` is the control group
it runs in right now. `rlimits` has every resource limit, the ones
from `rlimit` and the ones the service inherits. A `tty` has a `tty`
object with its device and flags where other types have `log`.
`internal` is state Finit keeps for its own use, it may change between
releases.
Left out when they do not apply are `environment`, `condition`, `exit`,
`if`, `provides`, `conflicts`, `groups`, `capabilities`, `pam`, and the
cgroup members `cgroup`, `memory`, `cpu`, and `limits`.
```
alpine:~# initctl -j status dialer | jq .restart.delay