noatime and tmpwatch: oops
Filed under: linux noatime tmpwatchfrom "man tmpwatch":
Make the decision about deleting a file based on the file's atime (access time). This is the default.
Combine this with a common trick of turning atime off on filesystems and you have a recipe for breaking things that expect their temporary files and directories to be around when they need them. I configure Nginx to put its temp files under /var/tmp/nginx, but that directory kept disappearing. I added code to build the directory tree when Nginx is started, but they would disappear while it was running. Turns out that noatime is the culprit, and tmpwatch is the unwitting accomplice.
There's a few ways to fix this issue:
- Put your temp files somewhere else.
- Use relatime rather than noatime. Unfortunately relatime is only available in newer kernels (2.6.18 doesn't have it).
- Change tmpwatch to use --ctime. There's a nice writeup on this here.
In the case of Nginx, I actually decided to move the temp files to /var/run/nginx. Since the files in question are actually temporary buffers that Nginx manages on its own, this seemed the right solution.






