I’m not kidding and I’m not amused … but I really need to understand why the following /etc/tmpfiles/tmp.conf:
# This file overwrites systemd defaults in /usr/lib/tmpfiles.d/tmp.conf
#
# See tmpfiles.d(5) for details
# Clears /tmp and /var/tmp and creates /tmp/.cache
D /tmp 1777 root root 1s
d /var/tmp 1777 root root 30d
d /tmp/.cache 1777 root root 1s
causes /tmp to be cleared not just at boot as I would expect … but randomly from time to time and, as you can imagine, always at the wrong moment. It hasn’t always been that way but for a couple months (I would say) on distros using systemd (openSUSE 12.1/12.2 and Fedora).
Carlos - in case you read this post - I know that I have to fill a bug report …
I vaguely mentioned this behaviour in several posts. But it desserved a new thread.
Note that it should be “/etc/tmpfiles.d/tmp.conf”. If you really have the path that you have listed, then that’s the problem right there.
It works for me, but I do not have that “.cache” line. I wonder whether the “d” should be a “D” at the start of your “.cache” line, for I would think that a “d” is possibly in conflict with the “D” in the “/tmp” line.
No I don’t. That was a typo. Thanks for correcting.
Humm … I guess I’m going to comment out that line and wait a day or two. But I have the impression that this service gets re-started several times, not just at boot, because that’s how /tmp gets cleared, without a special reason - it just happened quite often lately, with the consequence that users TMPDIR (/tmp/username ) are gone and everyhting which needs to access these directories (such as browsers for caching, pulseaudio or other daemons started by users) stop working.
Something similar applies to all software which need creation/cleaning of certain runtime files and directories at boot, for example beneath the /run hierarchy (i.e. /var/run as it used to be known). These projects should just drop in configuration files in /etc/tmpfiles.d, also from the upstream build systems. This also helps speeding up the boot process, as separate per-project SysV shell scripts which implement trivial things like registering a binary format or removing/creating temporary/volatile files at boot are no longer necessary.
So, is it as simple as adding the required ‘tmp cleaning’ script here, as the developers intended? It would be nice if they simply added ‘onboot’ as an age option, rather than the ‘cron-like’ options they’ve currently provided.
I wasn’t reading closely enough. When I look at my file “/etc/tmpfiles.d/tmp.conf” I see (as the last few lines):
# Clear tmp directories separately, to make them easier to override
D /tmp 1777 root root 10d
d /var/tmp 1777 root root 30d
So I have a “10d” there, and you have “1s”
So I don’t think user files in “/tmp” will be deleted here until they have been untouched for 10 days, or until the next boot, whichever comes first. Your “1s” looks too short to me.
We already discussed this in another thread couple months ago, if you remember. I know that you have 10 days, but it’s not what I want. I want 1 second because I want /tmp to be entirely cleared at boot (not only files that are older than 10 days). But I also want it to be cleared only once at boot and not randomly on running systems. Notice that it used to work - but some systemd update must have broken it.
You have this:
D /tmp 1777 root root 10d
d /var/tmp 1777 root root 30d
I have this:
D /tmp 1777 root root 1s
d /var/tmp 1777 root root 30d
and the default is this:
d /tmp 1777 root root 10d
d /var/tmp 1777 root root 30d
The difference between d and D can be read in man tmpfiles.d.
But in my case, it is cleared entirely at boot. My understanding of the “D” is that it implies to clear entirely at boot, and to use the time given for additional cleanings before the next boot. I’ll grant that the wording in the man page is not as clear as it could be.
If you change that “1s” to “10d” (or even “3d” if you like shorter), then I think you will get what you want.
tmpfiles.d is processed by systemd-tmpfiles-clean.service, which in turn gets called by systemd-tmpfiles-clean.timer which contains
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
Therefore your /tmp gets clean 15 min after boot, and approximately once a day. Maybe the latter is what you experience as “cleared randomly”. You might want to create your personal version of systemd-tmpfiles-clean.timer in /etc/systemd/system.
You’re welcome! Thanks for this friendly feedback.
So, whoever stumbles upon this thead in search for tmp cleanup solutions: keep in mind that there are currently two tmp cleaning mechanisms in openSUSE:
/etc/cron.daily/suse.de-clean-tmp which is controlled by /etc/sysconfig/cron
The tmpfiles.d mechanism which comes with systemd, controlled by /{usr/lib,etc}/tmpfiles.d
I am no expert and don’t have much technical savvy, but according to the man page (man tmpfiles.d), doesn’t “d” mean to create a directory if it doesn’t exist, and “D” means to create or empty a directory? So, to empty both directories the code would be (with the number of days being open to choice):
D /tmp 1777 root root 1d
D /var/tmp 1777 root root 10d
The man page seems to suggest that if you want to delete the contents of the tmp directory at boot you could have the following:
D! /tmp 1777 root root 0
D /var/tmp 1777 root root 10d
D /tmp 1777 root root 7d
d /var/tmp 1777 root root 14d
and that seems to be working well. “/tmp” gets cleaned at boot. If I am understanding it correctly, anything older than 7 days will also be cleaned out. I usually reboot twice a week, so that doesn’t get tested. And “/var/tmp” is not cleared at boot, but anything older than 14 days should be cleared.
The man page seems to suggest that if you want to delete the contents of the tmp directory at boot you could have the following:
D! /tmp 1777 root root 0
D /var/tmp 1777 root root 10d
That’s the Arch documentation. They do things a little differently. They seem to have permanently wired into “systemd”, that it should mount “/tmp” from ram/swap, so the “D!” is suggested to override that.
My main query was the function of “D” versus “d”. When I last posted, “D” was clearing /tmp at boot, but “d” didn’t seem to work. Now I find that “d” is working, clearing /tmp after the specified number of days, but not at boot. So, it appears that “D” clears at boot and after the specified number of days if the system is not turned off, while “d” doesn’t clear at boot, but will clear after the specified number of days. Is that correct?
The man page (man tmpfiles.d) seems to say otherwise, which is confusing. It says:
“d Create a directory if it does not exist yet.”
“D Create or empty a directory.”
Am I overlooking something here?
If only the administrators of openSUSE would provide comprehensive and authoritative documentation on this matter.
AIUI, ‘D’ empties the directory unconditionally during boot, whereas ‘d’ does not (and both create it if it doesn’t exist). But in both cases it should get cleaned regularly by systemd-tmpfiles-clean.service, according to the “age” value specified in tmp.conf, i.e the “10d” or “1s” in the previous posts.
Yes, that’s correct. And that’s how I read the man page. I take the part about “d” and “D” to be in addition to the cleaning of old files, not as an alternative to that cleaning.
Yes.
The point is that tmpfiles.d is not only used for cleaning up temporary files/directories, but also for creating them in the first place (necessary for a tmpfs e.g.).
The ‘d’/‘D’ specifies how to create a directory (during boot), whereas the “Age” (e.g. “10d”) specifies which files/directories in it should be deleted by systemd-tmpfiles-clean.service (this runs once a day/15min. after boot and deletes all files older than the specified age).
And IIUIC, ‘D’ will remove everything in the directory during boot, regardless of its age.