Reintroduce ExitTypev249.8
commit31b7eefb6c3c8e3da74ef18d864e64d72f542e16
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 11 Jan 2022 19:45:42 +0000 (11 20:45 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 11 Jan 2022 19:52:54 +0000 (11 20:52 +0100)
tree0fa0190390d4ee8f5afd0a90dc8d71093c9382da
parenta82b93092bdd3901a22375a820bfa09db8a39978
Reintroduce ExitType

This introduces `ExitType=main|cgroup` for services.
Similar to how `Type` specifies the launch of a service, `ExitType` is
concerned with how systemd determines that a service exited.

- If set to `main` (the current behavior), the service manager will consider
  the unit stopped when the main process exits.

- The `cgroup` exit type is meant for applications whose forking model is not
  known ahead of time and which might not have a specific main process.
  The service will stay running as long as at least one process in the cgroup
  is running. This is intended for transient or automatically generated
  services, such as graphical applications inside of a desktop environment.

Motivation for this is #16805. The original PR (#18782) was reverted (#20073)
after realizing that the exit status of "the last process in the cgroup" can't
reliably be known (#19385)

This version instead uses the main process exit status if there is one and just
listens to the cgroup empty event otherwise.

The advantages of a service with `ExitType=cgroup` over scopes are:
- Integrated logging / stdout redirection
- Avoids the race / synchronisation issue between launch and scope creation
- More extensive use of drop-ins and thus distro-level configuration:
  by moving from scopes to services we can have drop ins that will affect
  properties that can only be set during service creation,
  like `OOMPolicy` and security-related properties
- It makes systemd-xdg-autostart-generator usable by fixing [1], as obviously
  only services can be used in the generator, not scopes.

[1] https://bugs.kde.org/show_bug.cgi?id=433299

(cherry picked from commit 596e447076b27d103a30c26a68626e9820ac705b)
17 files changed:
docs/TRANSIENT-SETTINGS.md
man/org.freedesktop.systemd1.xml
man/systemd.service.xml
shell-completion/bash/systemd-run
shell-completion/zsh/_systemd-run
src/core/dbus-service.c
src/core/load-fragment-gperf.gperf.in
src/core/load-fragment.c
src/core/load-fragment.h
src/core/service.c
src/core/service.h
src/shared/bus-unit-util.c
test/TEST-56-EXIT-TYPE/Makefile [new symlink]
test/TEST-56-EXIT-TYPE/test.sh [new file with mode: 0755]
test/fuzz/fuzz-unit-file/directives.service
test/units/testsuite-56.service [new file with mode: 0644]
test/units/testsuite-56.sh [new file with mode: 0755]