Linux – symlinks on shared storage

filesystemsglusterfslinuxsymbolic-link

Say I have a glusterfs mount that is shared between multiple servers, which is accessed by an application, and logs are written to a directory that would normally be in the directory tree of that mount point. (say /foo is our mounted shared storage, and /foo/bar is the directory where logs are written to)
In order to prevent all servers from trying to write to the same logfile, I want to make /foo/bar a symlink to another, local directory, /var/bar.
Is it possible to make local symlinks on a shared storage mount? And would those symlinks be able to be mapped on other servers that access that storage?
Or if not, is there another way around this, like loop devices? Assume changing the directory to which logs are written is not possible.

Best Answer

If the filesystem supports symbolic links, then symbolic links (according to the POSIX standard) are interpreted on the client, not the server. Therefore you should be able to symlink to other filesystems reliably on any Unix or Unix-like system such as Linux.

For example:

/foo        A gluster remote file system
/var        A local file system

If /foo/bar is a symlink to /var/log/myhost then every machine that writes to /foo/bar will write to the local /var/log/myhost on that machine.

However if /var/log doesn't exist, the write will fail with an error message that will surprise you. (give it a try) So, make sure /var/log exists. That's not a problem as /var/log is created at install time in most systems. However, what if the link was to /var/log/dirname/filename.txt there is a good chance that /var/log/dirname doesn't exist yet. I've run into this problem before.

(I think there are examples of this in Chapter 28 of The Practice of System and Network Administration where there are recommendations to link to /etc/ from networked file systems.)

So, yes, you can do this with symlinks. However you it may confuse coworkers. Is it possible to tell the software to just write to /var/log/foo? It will be less confusing and more sustainable. You coworkers will thank you.