Jacob
Jacob

Reputation: 6487

Files don't update in vagrant when saved on host computer?

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.

Upvotes: 3

Views: 2179

Answers (4)

tinko silo
tinko silo

Reputation: 11

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.

Upvotes: -2

Jacob
Jacob

Reputation: 6487

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

Upvotes: 6

regilero
regilero

Reputation: 30536

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

Upvotes: 2

NexWarner
NexWarner

Reputation: 91

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

Upvotes: 1

Related Questions