5

The documentation I have read on systemd unit files states that unit files can be found in three locations on the filesystem:

  1. /etc/systemd/system/: system unit files
  2. /run/systemd/system/: runtime unit files
  3. /lib/systemd/system/ (also sometimes /usr/lib/systemd/system/): default unit files for packages

I understand that system unit files are for (possibly user-configured) system daemons. I also understand that default package unit files are unit files that come along with package installs that provide sane defaults.

However, I cannot find documentation that explains the purpose of runtime unit files. What are runtime unit files for? Might I, as a sysadmin, ever create one? What are some examples of problems that might be solved with runtime unit files? Why do runtime unit files take precedence over package unit files, but not over system unit files?

  • _The documentation I have read on systemd unit files states that unit files can be found in three locations on the filesystem_ - which documentation? – eleventyone Jul 22 '20 at 19:35
  • Don't worry too much eleventyone, [It was actually nine locations, even more now, and the systemd doco erroneously missed one anyway](http://jdebp.uk./FGA/systemd-documentation-errata.html#MissingUsrLocalLibSystemd). – JdeBP Jul 24 '20 at 08:10

4 Answers4

1

Historically, runtime unit files are intended for machine-generated units. They are supposed to override corresponding vendor units (if any), but are designed to allow user overrides, hence the defined precedence.

Nowadays I think they’ve largely been supplanted by transient units generated using the bus API; these don’t appear as files anywhere.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
0

I've never seen /run/systemd being used for unit files on my systems. Although it could be used when you're just running unmodified unit files from /lib/systemd.

Usually /lib/systemd contains the default unit files and timers (and you should never edit them there), and /etc/systemd contains the enabled (links to /lib/systemd files) and customized ones.

You can customize timers and unit files with sudo systemctl edit unit/timer to add some things to the original file or sudo systemctl edit --full unit/timer to completely edit the unit file or timer.

aardbol
  • 643
  • 7
  • 16
  • 1
    You should look harder. (-: https://unix.stackexchange.com/a/233581/5132 https://unix.stackexchange.com/a/332797/5132 – JdeBP Jul 24 '20 at 08:06
0

From reading the manual here it appears that runtime unit files are simply another type of systemd configuration file, for a given process.

Also, they are generated at runtime and deleted upon exiting the process.

If it helps, search "run" on that page and read all the entries. From there, it is easy to reach the same conclusion.

BitShift
  • 131
  • 1
  • 12
0

The runtime files in /run/systemd/system stem from the ability to make modifications to a process (unit) during the current boot without that change/modification persisting across a reboot.

From systemctl.1:

--runtime
           When used with enable, disable, edit, (and related commands),
           make changes only temporarily, so that they are lost on the
           next reboot. This will have the effect that changes are not
           made in subdirectories of /etc/ but in /run/, with identical
           immediate effects, however, since the latter is lost on
           reboot, the changes are lost too.

           Similarly, when used with set-property, make changes only
           temporarily, so that they are lost on the next reboot.
CG3
  • 101
  • 1