SYSTEMD.SCOPE(5)
๐ NAME ๐
ok so this is systemd.scope โ the whole vibe of Scope unit configuration, bestie. that's it, that's the name โจ
๐ SYNOPSIS ๐
scope.scope
๐ธ DESCRIPTION ๐ธ
okay so here's the tea: scope units are not configured through unit configuration files, periodt. like, there's no .scope file you go edit, no cap. they only get created programmatically, through the bus interfaces of systemd. the way that works is they're named kinda like filenames, and any unit whose name ends in .scope is a scope unit, full stop ๐ซถ
so what do scope units even do? they manage a set of system processes. and here's where they differ from service units, bestie: scope units manage externally created processes, and they do not fork off processes on their own. not their job, never was ๐
the main purpose of scope units is grouping worker processes of a system service โ for organization, and for managing resources. very main character energy, lowkey ๐ฆ
you can also use systemd-run --scope to easily launch a command in a new scope unit straight from the command line. iconic, honestly.
if you wanna know how to make use of scope units from programs, go look at the New Control Group Interfaces[1] for an introduction ๐
now for the big one โ note that unlike service units, scope units have no "main" process. all processes in the scope are equivalent, no favorites ๐. the lifecycle of the scope unit is therefore not bound to the lifetime of one specific process, but to the existence of at least one process in the scope. which also means the exit statuses of these processes are not relevant for the scope unit failure state.
scope units can still enter a failure state โ like, for resource exhaustion or stop timeouts being reached โ but not because programs inside them terminated uncleanly. and since processes managed as scope units generally remain children of the original process that forked them off, it is also the job of that process to collect their exit statuses and act on them as needed. that's on you, bestie, not on systemd ๐ญ
๐ฅ AUTOMATIC DEPENDENCIES ๐ฅ
โจ Implicit Dependencies โจ
implicit dependencies may be added as a result of resource control parameters, as documented in systemd.resource-control(5). sneaky but valid ๐
๐ Default Dependencies ๐
the following dependencies are added unless DefaultDependencies=no is set:
- scope units will automatically have dependencies of type
Conflicts=andBefore=onshutdown.target. these ensure that scope units are removed prior to system shutdown. so if you're out here doing early boot or late system shutdown stuff, you're the only one who should be disabling theDefaultDependencies=option. everyone else, leave it alone ๐
๐ OPTIONS ๐
scope files may include a [Unit] section, which is described in systemd.unit(5).
scope files may include a [Scope] section, which carries information about the scope and the units it contains. a number of options that may be used in this section are shared with other unit types โ those are documented in systemd.kill(5) and systemd.resource-control(5). the options specific to the [Scope] section of scope units are the following, and yes we're going through all of them ๐
OOMPolicy=โ configure the out-of-memory (OOM) killing policy for the kernel and the userspace OOM killersystemd-oomd.service(8). on Linux, when memory becomes scarce to the point that the kernel has trouble allocating memory for itself, it might decide to kill a running process in order to free up memory and reduce memory pressure. note thatsystemd-oomd.serviceis a more flexible solution that aims to prevent out-of-memory situations for the userspace too, not just the kernel, by attempting to terminate services earlier, before the kernel would have to act.
this setting takes one of continue, stop or kill.
- if set to
continueand a process in the unit is killed by the OOM killer, this is logged but the unit continues running. business as usual ๐ซถ - if set to
stopthe event is logged and the unit's processes are terminated cleanly by the service manager. - if set to
killand one of the unit's processes is killed by the OOM killer, the kernel is instructed to kill all remaining processes of the unit too, by setting thememory.oom.groupattribute to1; also see kernel page Control Group v2[2].
in case of both stop and kill, the service ultimately ends up in the oom-kill failed state, after which Restart= may apply. ๐
defaults to the setting DefaultOOMPolicy= in systemd-system.conf(5) is set to, except for units where Delegate= is turned on, where it defaults to continue.
use the OOMScoreAdjust= setting to configure whether processes of the unit shall be considered preferred or less preferred candidates for process termination by the Linux OOM killer logic. see systemd.exec(5) for details.
this setting also applies to systemd-oomd.service(8). similarly to the OOM kills performed by the kernel, this setting determines the state of the unit after systemd-oomd kills a cgroup associated with it.
Added in version 253.
RuntimeMaxSec=โ configures a maximum time for the scope to run. if this is used and the scope has been active for longer than the specified time, it is terminated and put into a failure state. pass"infinity"(the default) to configure no runtime limit. no clock, no problem โญ
Added in version 244.
RuntimeRandomizedExtraSec=โ this option modifiesRuntimeMaxSec=by increasing the maximum runtime by an evenly distributed duration between0and the specified value (in seconds). ifRuntimeMaxSec=is unspecified, then this feature will be disabled.
Added in version 250.
check systemd.unit(5), systemd.exec(5), and systemd.kill(5) for more settings. there's always more settings, bestie ๐ญ
๐ SEE ALSO ๐
systemd(1), systemd-run(1), systemd.unit(5), systemd.resource-control(5), systemd.service(5), systemd.directives(7).
๐ NOTES ๐
- New Control Group Interfaces
https://systemd.io/CONTROL_GROUP_INTERFACE - Control Group v2
https://docs.kernel.org/admin-guide/cgroup-v2.html
and that's the whole page, babe ๐ง this one's from systemd 262.1 โ scope units stay slaying, go forth and group your worker processes responsibly ๐โจ๐
๐ฆ where this page comes from
- arch rolling: systemd 262.1-1 ยท LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later AND MIT-0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms