Score:1

Can't write to /tmp in systemd service with PrivateTmp=true

in flag

My apache2 service has PrivateTmp=true. When the service first starts it works fine, but after a few days, writing to /tmp fails with "no such file or directory". To debug I've tried running nsenter -t <apache-pid> -m bash and I've confirmed that /tmp exists, but mkdir /tmp/test fails with "no such file or directory". I'd rather not remove the PrivateTmp=true directive.

If I restart the service it starts working again.

The mount line for /tmp inside says it is mounted to /dev/nvme0n1 which seems odd to me, but that is the case both when /tmp is working immediately after starting the service and when it is not writable.

Anyone know why /tmp suddenly becomes unwritable?

Score:2
in flag

I found the problem.

I had tmpreaper enabled and configured to clean up old files and directories under /tmp. I didn't have an exclude rule for /tmp/systemd-private-*, so tmpreaper was deleting the private tmp directory for apache2.

Score:0
zw flag

As I understand it PrivateTmp=true forbids exactly what you tried when you were debugging. The daemon will create it's own subdirectory and change it's namespace accordingly.

As your problem only occurs after some time I have the following advice: Make sure the application cleans up and does not store large files in the virtual /tmp directory. As far as I know this directory is using RAM, no persistent file system. You have limited space here.

You might want to log the /tmp directories size for a while. If it keeps growing that's the issue.

cn flag
??? /tmp is a normal direcory with specific right it is in the /etc/fstab file. So, this statement seems false to me.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.