1

I'm working with an external service that creates its own systemd scopes like system.slice/someapp.slice/instance-400.scope or user.slice/user-1000.slice/app-1234.scope.

The scope names embed the pid, so they are dynamic. The Id and Name both match the unit name exactly.

Does systemd offer any way to write a .scope unit file that will apply [Scope] properties to all instances of the scope by name pattern matching it, or is this something that can only really be done with the cooperation of the launching app?

Details/related at: Applying systemd control group resource limits automatically to specific user applications in a gnome-shell session

Craig Ringer
  • 10,553
  • 9
  • 38
  • 59

1 Answers1

2

Drop-in files seem to allow this kind of override. See man systemd.unit or this documentation, cited below. I think the key functionally which will allow the drop-in to apply while ignoring the dynamic part (PID) is:

Moreover for unit names containing dashes ("-"), the set of directories generated by repeatedly truncating the unit name after all dashes is searched too. Specifically, for a unit name foo-bar-baz.service not only the regular drop-in directory foo-bar-baz.service.d/ is searched but also both foo-bar-.service.d/ and foo-.service.d/. This is useful for defining common drop-ins for a set of related units, whose names begin with a common prefix.

I was able to create such an override for the user slice using the following (note the lack of PID after the last dash):

~$ systemctl --user edit --force app-.scope

Which open a file editor where you can add your extra options. For example:

[Scope]
OptionOne=value
OptionTwo=value

You can confirm the presence of the drop-in using:

~$ systemctl --user status app-1234.scope
[...]
Drop-In: /home/foo/.config/systemd/user/app-.scope.d
             └─override.conf
[...]

For the system slice the approach is likely similar, except for the the --user flag passed to systemctl.

VLD
  • 21
  • 2