Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
systemd-tmpfiles reads rule files from /usr/lib/tmpfiles.d/ (packages), /run/tmpfiles.d/ and /etc/tmpfiles.d/ (yours; a file with the same name here replaces the package file). Each line is one rule: type, path, mode, user, group, age, argument.
At boot, systemd-tmpfiles-setup.service runs --create (make folders and files, for example in /run). Every day, systemd-tmpfiles-clean.timer runs --clean: files older than the age of their rule are deleted. RHEL's own rules clean /tmp after 10 days and /var/tmp after 30 days.
Zo schrijf je het
systemd-tmpfiles [OPTION]... [CONFIG-FILE]...Belangrijkste delen
Line types (tmpfiles.d)
dPATHMODEUSERGROUPAGE- Create a folder; with AGE, clean old files in it.
DPATH…- Like
d, but empty the folder at every boot (--remove). ePATH…- Clean an existing folder by age; do not create it.
v/q/QPATH…- Create a folder or btrfs subvolume (with quota).
fPATHMODEUSERGROUP-TEXT- Create a file if missing (with TEXT as content).
FPATH…- Create or empty a file.
wPATH----TEXT- Write TEXT into an existing file (for example in /sys or /proc).
LPATH----TARGET- Create a symbolic link.
CPATH----SOURCE- Copy a file or folder if the target is missing.
xPATH- Do not clean this path (exception).
XPATH- Do not clean this path, but clean what is inside.
r/RPATH- Remove the path (
R= with content) at--remove. z/ZPATHMODEUSERGROUP- Fix rights, owner and SELinux label (
Z= recursive). t/TPATH----ATTR- Set extended attributes.
h/HPATH----ATTR- Set file attributes (like chattr).
a/APATH----ACL- Set POSIX ACLs.
Age
10d,12h,30m,1w- Age units: days, hours, minutes, weeks.
-- No cleaning.
Opties 17
Meest gebruikt
Actions
Scope
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1See all rules in use
2A folder for an app that must exist after every boot
echo 'd /run/myapp 0755 myapp myapp -' > /etc/tmpfiles.d/myapp.conf systemd-tmpfiles --create /etc/tmpfiles.d/myapp.conf ls -ld /run/myapp drwxr-xr-x. 2 myapp myapp 40 Oct 27 13:10 /run/myapp/run is empty after every reboot; the rule makes the folder again at boot.
3Delete old files automatically
echo 'd /var/tmp/cache 0750 root root 7d' > /etc/tmpfiles.d/cache.conf systemd-tmpfiles --clean /etc/tmpfiles.d/cache.confFiles in /var/tmp/cache older than 7 days are removed now and every day by the timer.
4Keep /tmp files longer than 10 days
cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf sed -i 's|^q /tmp 1777 root root 10d|q /tmp 1777 root root 30d|' /etc/tmpfiles.d/tmp.confThe file in /etc with the same name replaces the package file.
5Protect one folder from cleaning
echo 'x /tmp/build-keep' > /etc/tmpfiles.d/keep.conf6Empty a folder at every boot
echo 'D /var/lib/myapp/sessions 0700 myapp myapp -' > /etc/tmpfiles.d/sessions.conf7Make a link at boot
echo 'L /run/myapp.sock - - - - /var/lib/myapp/app.sock' >> /etc/tmpfiles.d/myapp.conf8Fix rights and SELinux labels at boot (DevSecOps)
echo 'Z /srv/app 0750 app app -' > /etc/tmpfiles.d/app-perms.conf systemd-tmpfiles --create /etc/tmpfiles.d/app-perms.conf9Check the daily cleaning timer
10Write a kernel setting at boot
echo 'w /sys/kernel/mm/transparent_hugepage/enabled - - - - never' > /etc/tmpfiles.d/thp.conf11User rules without root
Niets past bij dit filter.
Let op
- The age counts from the newest of access, change and modify time — a file that is read often is not cleaned.
--removedeletes for real. Test new rules with--cleanon a test folder first.- Rule paths must be absolute.
%h(home) and%U(user ID) work only in user rules.
Bestanden
/etc/tmpfiles.d/*.conf- Your rules (win over package rules with the same name).
/usr/lib/tmpfiles.d/*.conf- Package rules.
/run/tmpfiles.d/*.conf- Runtime rules.
~/.config/user-tmpfiles.d/- User rules.
Tips om te onthouden
- One line
d PATH MODE USER GROUP AGEcovers most tasks: "the folder must exist" and "old files must go". systemd-tmpfiles --cat-config | grep PATHshows which rule touches a path.
Exitcodes
0 | Success. |
65 | A rule has a syntax error (with --create etc. the rest still runs). |
73 | A file or folder could not be created. |
Other | Another error. |