last day (15 days later) » 

16:25
1
A: If `/tmp` is a symbolic link, it isn't wiped on reboot

Artur MeinildTemp files are cleaned in Ubuntu by systemd-tmpfiles and the related service /lib/systemd/system/systemd-tmpfiles-clean.service, and the configuration for said files can be configured inside /etc/tmpfiles.d/*.conf (also see this answer). To include the directory you describe, create a config file...

This doesn't seem to work. I created the file as you described and rebooted, and some old files I created a while ago are still there. Is there perhaps a way to see error messages that were produced during the normal operation of systemd-tmpfiles-clean.service?
To be honest, I haven't really messed that much with non-standard configuration of tmpfiles. Doesn't it work either if you manually run systemd-tmpfiles --clean?
I'll investigate this further on my own server when it reboots (which might be within a couple of weeks)..
Yeah, sudo systemd-tmpfiles --clean has exit code 0 and doesn't print anything, but the files remain.
I'll look into it some more.. If you stumble upon a solution, please let me know, or suggest an edit to my answer. It should be possible.. 🤔
Of course there's also the quick and dirty way by just making a cron command to clean it, but this would be more elegant (if it works).
I know about @reboot in crontab syntax, but it's not clear if it would run at the right time. I presume that clearing /tmp on startup is delicate because if it happens too late, you'll remove files that systemd needs for the current session.
16:25
Right - we have to get this to work..
The tmpfiles.d manpage suggests that e needs an age spec in order to cleanup ("If omitted or set to "-", no automatic clean-up is done.") ex. e /scratch/tmp/ - - - 0 ("If the age argument is "0", contents will be unconditionally deleted every time systemd-tmpfiles --clean is run")
@steeldriver thanks - Kodiologist try the revised solution, adding age parameter.
sudo systemd-tmpfiles --clean now works, but the clean still doesn't happen on reboot. Perhaps the service is run before /scratch is mounted, but I don't know what to do about that. /scratch is mounted in a seemingly normal way in /etc/fstab.
Well, a little progress.. 😬
This is strange, because my systemd-tmpfiles-clean.service already contains: After=local-fs.target. This should ensure it runs after local filesystems are mounted. Can you confirm your systemd-tmpfiles-clean.service contain that line?
Maybe you could add basic.target and see if that fixes the bootup cleanup?
@Kodiologist please check again - in my 22.04 system, the systemd-tmpfiles-clean.timer (which I believe is default) is configured to run 15 minutes after boot (OnBootSec=15min) and every 1d thereafter, so you may have looked too early?
16:25
@steeldriver great catch - thanks for all input! 👍
@steeldriver Oh hey, you're right. It does happen; it just takes like 15 minutes to happen. Thanks for your help.
Great to know it worked!
I've requested that comments are moved to chat, since this was a longer troubleshooting process..
... I guess you might want to change the 0 to something greater than 15mins in that case, else it might clean files that have been created after boot?
Good point - age should probably be set to 20 minutes then, to be sure..

last day (15 days later) »