I have following setup:
The problem: Watch task in grunt.js didn't see changes in mounted folder.
If I change files inside VM, watch task work normally. If I start grunt.js not from virtual box, but from main os it also works. Tried in Mac OS and Windows 7.
Problem only happens then task is started from VM, and files are changed from main OS. Is there a workaround to this problem?
Update. Some details about our usage scenarios, to better understand context:
We want to make it more straightworward. For it we trying to use Vagrant and a number of pre-configured OS images.
Right now project setup looks like this:
We like this setup and most of the time we didn't have any problems with it. But on our node.js projects we use some css and js preprocessors, and like to update their files in realtime. And there is the problem on initial post.
Solutions with access to files with ssh VM and with project's files inside VM will probably work, but they didn't solve the base problem (fast and easy setup of big number of projects across group of developer running different OS'es)
File/Path watchers depend on OS's lower level facilities like inotify on Linux or kqueue on BSD systems. These mechanisms work directly with the filesystem drivers and they will not see the changes on network mounts. If your script will work on the virtual OS, then you might change the direction of sharing. Instead of reaching a shared folder on host OS from inside the guest OS, use a real folder on guest OS (where the real action happens) and reach it from the host OS to edit your files. This way your guest OS will work as it would on its production environment, which is what Vagrant promises; but fails to deliver, apparently.
I personally use Sublime Text 2 editor with SFTP plugin. In this setup, I keep two copies of files and work on the ones on the host OS. Whenever I edit/add a file, my editor quickly uploads it to server, i.e the guest OS. When I move to production servers, I can still use the same approach which is better than using shared folders.
Before switching to Sublime as my main editor, I had been using Vim for more than a decade. At that time, instead of using Vim's sftp/ssh facilities, which were always buggy, I was using WinSCP as SFTP client. After you configure it properly, whenever you double click a file on the server, it opens it on your choice of editor and whenever you save the file, WinSCP automatically uploads it to server. This was very close to what I have with Sublime's SFTP plugin; however the local (host OS) versions of files were created on temporary folders WinSCP creates on the fly.
The approach Sublime's SFTP plugin has, which is having duplicates of folders on both systems fits my needs better because I have also SpiderOak running as my backup solution on the host OS. I love it since it keeps version history of files. I set it up to check changes once an hour, instead of constantly watching to make it perform smoother risking losing work of an hour in case of a system failure. Everything works perfectly in this setup and I have really used its old-versions feature more than a few times which saved me from a lot of drudgery and loss of work.
So, in summary, if you want to continue working on shared folders, what you will do is to install and configure a Samba/NFS/FTP server on guest OS (your Ubuntu) and share the folders. Then you will access the network share from host OS (your Mac/Win7) the same way you access any other shared remote folders. If your use and needs are similar to mine, then I strongly recommend you going with either Sublime+SFTP or YourEditor and WinSCP or a similar SFTP client.
UPDATE: Based on especially the symptom summarized as "If I change files inside VM, watch task work normally. If I start grunt.js not from virtual box, but from main os it also works." in the question, I made a wrong assumption about how grunt.js watches files and folders. I thought it was using node's fs.*watch functions; but as pyfunc showed with a well done research, my assumption was wrong. Although this does not affect the outcome of any suggestion I made, it was a wrong technical information I have to apologize for. So, it looks like the problem is caused by the modification times on files not being set correctly when modification is done on remote machine which may render vboxfs useless for this kind of use that depends on modification times of files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With