Our low-rent approach to verifying that NFS mounts are there

October 9, 2015

Our mail system has everyone's inboxes in an old-fashioned /var/mail style single directory; in fact it literally is /var/mail. This directory is NFS mounted from one of our fileservers, which raises a little question: how can we be sure that it's actually there? Well, there's always going to be a /var/mail directory. But what we care about is that this directory is the actual NFS mounted filesystem instead of the directory on the local root filesystem that is the mount point, because we very much do not want to ever deliver email to the latter.

(Some people may say that limited directory permissions on the mount point should make delivery attempts fail. 'Should' is not a word that I like in this situation, either in 'should fail' or 'that failure should be retried'.)

There are probably lots of clever solutions to this problem involving advanced tricks like embedded Perl bits in the mailer that look at NFS mount state and so on. We opted for a simple and low tech approach: we have a magic flag file in the NFS version of /var/mail, imaginatively called .NFS-MOUNTED. If the flag file is not present, we assume that the filesystem is not mounted and stall all email delivery to /var/mail.

This scheme is subject to various potential issues (like accidentally deleting .NFS-MOUNTED some day), but it has the great virtue that it is simple and relatively bulletproof. It helps that Exim has robust support for checking whether or not a file exists (although we use a hack for various reasons). The whole thing has worked well and basically transparently, and we haven't removed one those .NFS-MOUNTED files by accident yet.

(We actually use this trick for several NFS-mounted mail related directories that we need to verify are present before we start trying to do things involving them, not just /var/mail.)

(I mentioned this trick in passing here, but today I feel like writing it up explicitly.)

Sidebar: our alternate approach with user home directories

Since user home directories are NFS mounted, you might be wondering if we also use flag files there to verify that the NFS mounts are present before checking things like .forward files. Because of how our NFS mounts are organized, we use an alternate approach instead. In short, our NFS mounts aren't directly for user home directories; instead they're for filesystems with user home directories in them.

(A user has a home directory like /h/281/cks, where /h/281 is the actual NFS mounted filesystem.)

In this situation it suffices to just check that the user's home directory exists. If it does, the NFS filesystem it is in must be mounted (well, unless someone has done something very perverse). As a useful side bonus, this guards against various other errors (eg, 'user home directory was listed wrong in /etc/passwd').

Written on 09 October 2015.
« Why you (probably) want to have blog categories (and topics and more)
How much space ZFS reserves in your pools varies across versions »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Oct 9 01:35:05 2015
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.