You're drilling down into a very good detail there! systemd-tmpfiles is indeed the modern approach for cleaning /tmp and other temporary directories.
systemd-tmpfiles configuration files are simple text files that describe how systemd should handle various temporary, volatile, and transient files and directories at boot, during runtime, and during system cleanups.
Here's a breakdown of what they are and their significance:
Purpose:
- Create directories/files: They can specify directories and files to be created (e.g., ensuring a specific temporary folder exists with correct permissions).
- Set permissions/ownership: Define the permissions, ownership, and SELinux contexts for these files/directories.
- Clean up old files: Most importantly for our discussion, they specify which files/directories should be deleted or emptied based on their age (e.g., "delete everything in
/tmpolder than 10 days").
Location:
- These configuration files are typically found in:
/usr/lib/tmpfiles.d/: For configuration snippets provided by installed packages. These are usually not meant to be modified by users./etc/tmpfiles.d/: For local configuration overrides or custom rules created by administrators./run/tmpfiles.d/: For dynamic or runtime configuration.
- Files usually have a
.confextension (e.g.,tmp.conf,apache.conf).
- These configuration files are typically found in:
Syntax:
- They consist of lines, where each line defines a specific action.
- Each line starts with a type letter (e.g.,
dfor directory,ffor file,rfor remove,Zfor recursively set permissions,Cfor copy if missing) followed by arguments like path, mode, UID, GID, age, and argument.
Example (Simplified):
# Type Path Mode UID GID Age Argument d /tmp 1777 root root 10d -d: Create a directory if it doesn't exist./tmp: The path to the directory.1777: Permissions (sticky bit set, meaning users can delete only their own files).root: Owner (user).root: Group.10d: Age for cleanup. This is the crucial part for/tmpcleaning. It means files/directories older than 10 days in/tmpwill be removed bysystemd-tmpfiles. If set to0or-it implies no age-based cleanup for this entry, but other rules might still apply.-: Argument (often ignored for directories).
How they are used for cleaning
/tmp:- When your system boots,
systemdreads these configuration files. It uses them to ensure that directories like/tmp(and others) are set up correctly with the right permissions and ownership. - More importantly, a
systemdservice calledsystemd-tmpfiles-clean.serviceruns periodically (e.g., daily, or based on specific timers) to perform the actual cleanup operation based on theAgeparameter specified in these configuration files. This is how old files in/tmpget deleted automatically.
- When your system boots,
So, in essence, these .conf files are recipes for systemd to manage the lifecycle of temporary files and directories, ensuring system hygiene and proper operation.
Do you want to see an example of inspecting one of these files on your LabEx VM?