English
Tmpfiles.d
Overview
tmpfiles.d is a service for managing temporary files and runtime directories for daemons. In this guideline we mainly concentrate on how it is used to populate `+/run+` and `+/run/lock+`. Since `+/run+` is a `+tmpfs+` filesystem, it and its contents must be recreated on every reboot. For files intended to be created there, this should normally not pose any problems. However, directories will often need to be created ahead of time. This is best done using the tmpfiles.d mechanism.
tmpfiles.d configuration
Asking the tmpfiles.d mechanism to create directories for you just involves dropping a file into `+%{_tmpfilesdir}+`. You will need a build dependency on systemd-rpm-macros in order to make use of this macro.
For example, if the package needs a few directories to be created in `+/run+` in order for it to run, the packager needs to create a file named `+%{name}.conf+` that is installed as `+%{_tmpfilesdir}/%{name}.conf+`. The file has one or more lines of the following format:
d /run/NAME PERM USER GROUP -
The format of the line is as follows:
`+d+` specifies that a directory is to be created if it doesn't exist. You can use a different type specifier if you need it. See `+man tmpfiles.d+` for possible values.
`+/run/NAME+` is the filesystem path to create.
`+PERM+` are the permissions (in the 4-digit octal format) to apply to the directory when it is created.
`+USER+` is the name of the owner of the directory.
`+GROUP+` is the name of the group of the directory.
`+-+` specifies that aging should not be applied to the contents of the directory. Aging is a mechanism for automated cleanup of files that were not used for a specified length of time. This is mostly useful for directories such as /tmp and is seldom used by packages. Feel free to use aging if it is appropriate for your directory.
An example:
d /run/mysqld 0755 mysql mysql -
Information on other options is available on the https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html[tmpfiles.d man page] should you need to do something more advanced.
Example spec file
In the spec file, the packager needs to install the tmpfiles.d conf file into the `+%{_tmpfilesdir}+` directory and also make sure the directory is included in the rpm.
# For the _tmpfilesdir macro.
BuildRequires: systemd-rpm-macros