Skip to content

Instantly share code, notes, and snippets.

@fideloper
Last active February 29, 2016 06:23
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fideloper/dab171a2aa646e86b782 to your computer and use it in GitHub Desktop.
Save fideloper/dab171a2aa646e86b782 to your computer and use it in GitHub Desktop.
Sample Vagrant file. This installs Ubuntu 12.04 (64 bit). The use of NFS in this manner requires your user's password (needs sudo access). This optionally also has my LAMP server provisioning script (PHP 5.5).
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/var/www",
end
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/vagrant",
id: "core",
:nfs => true,
:mount_options => ['nolock,vers=3,udp,noatime']
# Optionally provision PHP
# config.vm.provision "shell", path: "https://gist.github.com/fideloper/7074502/raw/install.sh"
end
@fideloper
Copy link
Author

I have some issues when watching files (via Sass).

I have ruby/sass installed on the VM instead of on the host machine (my Mac).

If I use Sass to watch files within the Virtual machine while editing files on my host machine, Sass doesn't always see a change in the *.scss files.

This is alleviated if I both watch and edit files on the same machine (as that eliminates the use of NFS updating files between host and VM). That means I either need Sass on my mac, or to edit files directly on the server. (Which isn't a problem, just a note on how to make it work).

Supposedly, as per @EpocSquadron, we can/should use these flags for the NFS connection:

:mount_options => ['nolock,vers=3,udp,noatime,noac,lookupcache=none']

However, they don't seem to work.

  • noac - Attribute cache. This disables caching attributes such as file mode
  • noatime - Don't write to disk for access time
  • lookupcache - Turn off caching for file content. (This means using the network connection a lot more, but since this is all locally done on your loopback interface for the most part, it's not a big deal).

Anyone else run into this issue?

@mgustafsson1
Copy link

For me, it seems like
lookupcache=none
solved this problem (using the Virtual Box provider)

The Grunt watch task would sometimes need up to 20 seconds to detect changes in my .less files.

Besides Grunt watch, I also noticed delays when changing Blade templates or making other changes in my (Laravel) apps, which drove me nuts while debugging things - I never knew which version I was seeing in the browser.

After seeing your comment above I just added lookupcache=none and VOILÀ, Grunt watch detects the changes instantly! Hopefully this applies to the other problem I mentioned too.

So - thank you for the tip!!

UPDATE: Oops, seems like I wrote too soon. Changes are detected instantly, but this took my page requests from ~40ms to 2s. Not a dealbreaker on my local dev machine, but still... Maybe there's a value somewhere between lookupcache on and off. I'll dig into it.

UPDATE2: Admittedly, I have absolutely no idea what I'm doing, but after reading this:
http://www.sebastien-han.fr/blog/2012/12/18/noac-performance-impact-on-web-applications/
I used
:mount_options => ['actimeo=2']
and that seems to work great, both in terms of page speed and Grunt watch detecting changes more or less instantly.

@fideloper
Copy link
Author

That link is a good find, gonna read that over! Is your own mount option now 'actimeo=2' ?

@mgustafsson1
Copy link

Yes, this is my current setup:

Share an additional folder to the guest VM. The first argument is

the path on the host to the actual folder. The second argument is

the path on the guest to mount the folder. And the optional third

argument is a set of non-required options.

config.vm.synced_folder ".", "/vagrant",
:nfs => true,
:mount_options => ['actimeo=2']

@Ilyes512
Copy link

@mgustafsson1 definitely gona try that. I was also bothered by the huge latency of Grunt Watch and so I have been issuing the "Grunt" command to compile my sass files manually(almost when'd back to CodeKit).

edit:
Nice, it works! It's almost instant (1 to 2 sec max instead of the 9 to 10 seconds) :) Thanks for the tip! Will have to read your link and see what the other options do (ie nolock,vers=3,udp,noatime) and if I should add one of those in togather with actimeo.

@kmaxat
Copy link

kmaxat commented Mar 27, 2014

I had to add these lines to Vagrantfile to access localhost:8080

config.vm.network "forwarded_port", guest: 80, host: 8080

Am i doing this wrong?

@Ilyes512
Copy link

Ilyes512 commented Apr 1, 2014

@kmaxat
If you have something like this in you Vagrantfile:

config.vm.network :private_network, ip: "192.168.33.10"

Then you could use 192.168.33.10 instead of localhost:8080

@toychicken
Copy link

Hi - my understanding is that, because the watched files are on the host machine, but the gulp / grunt / etc processes are on the guest machine, that it's very unreliable because of the complexity of mapping the file system updates from the host OS, to a potentially wildly different guest OS.

It's small comfort, but if you can run the gulp / grunt / etc on your host machine, you should see better results, but obviously this isn't helpful if you're trying to run something like forever or nodemon.

@oldhobbyist
Copy link

@Ilyes512 Just tested, and that specific line is giving me error when doing vagrant up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment