Vagrant shared folder and file change events

file-sharingfilesystemsvagrantvirtual-machinesvirtualbox

I have ubuntu virtual machine that I'm accessing through Vagrant.
On my host (Mac OSX), there is a folder with couple of files, that I share to virtual machine. In that virtual machine, I want to use guard to watch for files changes and perform some action if any of those files changes.

I set up guard properly, and when changing shared file from within virtual machine, it works ok and runs appropriate scripts. But, if I try to change shared file from my host machine, this file change event doesn't propagate and guard doesn't react.

This is how my vagrant shared folder looks like (pretty usual stuff)

local_config.vm.share_folder "app", "/var/www/app/current", "../app"

I even tried using NFS sharing (:nfs => true) but it didn't help.

Is there any way to make file changes events propagate from host to virtual machine? Or is this something of Vagrant/VirtualBox nature?

UPDATE:

After some more trials, I installed ZenTest gem, which contains autotest tool allowing similar functionality regarding file change events.

When running autotest in virtual machine and changing files from my host machine, these changes are propagated and autotest reacts.

Based on this, it seems that the file change event propagation is an issue of guard, not vagrant or virtual box.

I haven't look into implementation differences between guard and autotest though.

Now I know it is possible to catch file change events from host in virtual machine. Does anyone have any idea on how to achieve this using guard? I like guard more because of its DSL and generic usability.

Best Answer

The root cause is that VirtualBox does not cascade the file change events on the host to the VM. Guard (on Linux) is expecting to receive notifications via inotify events. Instead, you can have guard poll for events with guard -p, but this can lead to your CPU maxing out, so you can throttle the polling back down with guard -p -l 10.

From guard help start:

  -l, [--latency=Overwrite Listen's default latency]
  -p, [--force-polling=Force usage of the Listen polling listener]

http://www.softr.li/blog/2012/07/21/running-guard-over-vagrant