core: add FileDescriptorStorePreserve=on-success option

Currently with FileDescriptorStorePreserve=yes the FD store is kept around
regardless of what happens to a unit, which is useful in many cases. But in
some cases, for example when complex services crash horribly, it's hard to
reason about what was in the intermediate state, and it's better to start
fresh.

Add a new 'on-success' option for the FileDescriptorStorePreserve= setting
that keeps it around only for as long as the unit doesn't go to a persistently
failed state.

This is especially useful in combination with LUO, where we don't want to
keep around LUO sessions created by units that then proceeded to crash and
burn, and might be in a bad state afterwards.
This commit is contained in:
Luca Boccassi
2026-05-21 10:14:08 +01:00
parent 00276b963c
commit 67dea1409b
9 changed files with 130 additions and 29 deletions
+4 -1
View File
@@ -123,7 +123,10 @@ This behavior can be modified via the
[`FileDescriptorStorePreserve=`](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#FileDescriptorStorePreserve=)
setting in service unit files. If set to `yes` the fdstore will be kept as long
as the service definition is loaded into memory by the service manager, i.e. as
long as at least one other loaded unit has a reference to it.
long as at least one other loaded unit has a reference to it. If set to
`on-success` the behaviour is the same as `yes`, except that the fdstore is
discarded once the service enters the permanent `failed` state, i.e. after all
automated restart attempts driven by `Restart=` have been exhausted.
The `systemctl clean --what=fdstore …` command may be used to explicitly clear
the fdstore of a service. This is only allowed when the service is fully