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?
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.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.