Vagrant, shared folder: take advantage of inotify over NFS
Asked Answered
M

3

13

Our Symfony2 webapp uses the Assetic watcher in development mode to re-compile assets on the go.

The webapp runs in a Docker container which runs in a Vagrant VM (Ubuntu 12.04 Precise). The host is OSX 10.9 Mavericks and it shares the code folder with the VM through a NFS (v3) share and the code is mounted in the container via a host/guest volume in Docker.

Since inotify seems to not be able to detect file modifications over NFSv3, the watcher works in polling mode which can be very slow (~1/2 minutes to detect the modification).

I've read that NFSv4 is inotify compliant but I did not found any good ressource on that.

Is there a way to make NFS/inotify works together?

Mikkimiko answered 17/1, 2014 at 16:13 Comment(0)
B
8

Unfortunately, inotify cannot work on NFS. inotify works by hooking itself in the VFS (virtual filesystem) layer, in the kernel. Whenever a modification happens, inotify knows about it, because the modification happens on the same machine, therefore in the same kernel — which makes the whole thing possible.

With NFS, modifications happen on the server, and notifications are expected on the client. But the NFS doesn't notify the clients when a change is made. Otherwise, it wouldn't scale. NFS has been designed (and operated) to have thousands of clients on a single server. Imagine if you do a tiny change, and the server has to push it to all clients!

Of course, you could say "hey, there should be a subscription mechanism in the NFS protocol, so that clients can tell the server that they want to know about changes happening in a specific location". Well, NFS was designed 30 years ago, so forgive them for not including this subscription/notification system :-)

I'm not familiar with Assetic, but maybe you could have a custom script to watch for changes manually, and re-compile assets each time you detect a change. Just walk through the directory containing the source for the assets, keep track of the mtime of each file in an associative array, and each time you detect a new file (or a new mtime), recompile. Boom!

See also this other SO question about inotify and NFS.

Benedetto answered 17/1, 2014 at 19:26 Comment(1)
Thanks for your detailed answer. We already have a polling script with Assetic, the one I mentioned as the "watcher" in my initial question but it's actually very slow (~1/2 min to detect changes).Mikkimiko
C
6

Here is a plugin which aim to solve this: https://github.com/mhallin/vagrant-notify-forwarder

Just install it and reload your boxes to have inotify notifications forwarded to your guests machine:

vagrant plugin install vagrant-notify-forwarder
Carlock answered 17/11, 2016 at 7:58 Comment(0)
I
2

You might be interested in this tool called Guard it listens to the file changes made on host OS, and then on Guest it pulls and update those. This worked for me, and now my assets are updated almost instantaneously.

https://serverfault.com/questions/453826/vagrant-shared-folder-and-file-change-events

Isobaric answered 27/10, 2015 at 3:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.