3

I'm using Vagrant as a Rails development environment. I only use the host computer to edit the files in sublime text (i.e. Ruby, Rails, Postgres and Nginx are all on the vagrant vm).

The problem is that if I make a small change in a file (1-3 characters), refreshing the browser doesn't show the update right away. I have to either restart nginx or add a few empty lines and save again to see the update.

What might be causing this? I've tried everything under the sun to resolve this.

Here is my vagrant file:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "xyz.box"
  config.vm.box_url = "http://domain.com/xyz.box"

  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder ".", "/vagrant", :nfs => true

  config.vm.provider "virtualbox" do |vb|
    vb.customize [
      "modifyvm", :id,
      "--memory", "1024",
      "--natdnsproxy1", "on",
      "--natdnshostresolver1", "on"
    ]
  end
end

I'm on Mac OS X and using Virtual Box as the provider. The vagrant box is Ubuntu 14.04.

Jacob
  • 6,317
  • 10
  • 40
  • 58

4 Answers4

6

It turned out the problem was Sublime Text's default "atomic save" feature that was creating this problem.

Adding the following to your Sublime Text preferences file will fix this:

"atomic_save": false

Jacob
  • 6,317
  • 10
  • 40
  • 58
  • 1
    I had hoped that this was the resolution to my issue, but [this answer](http://stackoverflow.com/a/20639093/195648) shows that since Build 3080 (March 2015), `atomic_save` has been turned off by default. (And I checked my Default preferences to make sure that was the case.) Red herring. – Curtis Gibby Jan 27 '16 at 16:54
2

This is a known problem for Apache and nginx with Virtualbox -- so also vagrant (@see this vagrant issue). The sendfile kernel mode does not refresh on the shared disk folders.

To fix it use this on nginx configuration:

sendfile off
regilero
  • 29,806
  • 6
  • 60
  • 99
1

Have you tried the "rsync" option? It shouldn't be difficult to setup and should be more reliable.

config.vm.synced_folder ".", "/vagrant", type: "rsync"

This feature is available from Vagrant 1.5.

https://www.vagrantup.com/blog/feature-preview-vagrant-1-5-rsync.html

NexWarner
  • 81
  • 2
  • 6
-2

Like Jacob said, turn off atomic save. I'd like to add that it is a very buggy and dangerous feature. If you're a sublime text 3 user, the first thing you should do is turn it off.