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.
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
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
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
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.
Related
I'm using Rails 7. I edit the files using Sublime Text on Windows 10. I have shared the folder where these files are located.
The Rails environment runs inside an Ubuntu Server VM using virtualbox. I use /etc/fstab to mount the cifs share containing the code base in Ubuntu. I have read and have all of these settings in development.rb:
config.cache_classes = false
config.reload_classes_only_on_change = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
config.public_file_server.headers = {
'Cache-Control' => "no-cache"
}
I access the development website through a VirtualBox host only network (i.e. 192.168.56.101:3000) using Firefox. I was having some trouble with files not update upon refresh, leading to some strange behavior. For anything other than views (controllers, models..etc) it seems to be working fine.
However, I'm now operating on the view templates and they are simply not updating, sometimes through many reloads of the page.
I have tried to make sure firefox is not caching them. Open the developer toolbar and disable HTTP caching.
I just opened Edge to see if it changes anything, and what do you know...even it's loading the old version of the view (without my changes). So Rails must be caching them, right? I did comment out the following lines:
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# config.file_watcher = ActiveSupport::FileUpdateChecker
Something tells me there's an issue maybe with listen and the cifs share...so I have tried uncommenting out the above config line in development.rb...
config.file_watcher = ActiveSupport::FileUpdateChecker
Supposedly this makes the listen gem use polling instead.
It still doesn't reload the views when I change them.
--UPDATE-- It seems to be an issue with the samba share (regarding the listen gem?)
Learned that file_watcher only works if reload_classes_only_on_change is enabled:
config.reload_classes_only_on_change = true
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
OR
config.file_watcher = ActiveSupport::FileUpdateChecker
I moved the code base onto the Ubuntu VM in the home directory. A.) it's faster. B.) The views update properly when I used nano to change a view.html.erb
I setup a samba share on Ubuntu and connect to it from the windows host, so I can still use sublime text. Had to add this line to my global .git_config under C:\Users[My User]
[safe]
directory = %(prefix)///192.168.56.101/[VM_shared_folder]/[My App]
%(prefix) is literal, replace the rest with your setup
Hope this helps.
I'm trying to increase the size of my vagrant virtual machine allowing me to build singularity without much success... I searched on internet and applied scrupulously different config but nothing makes.
Here is my Vagrant file :
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "sylabs/singularity-3.0-ubuntu-bionic64"
... (comment code)
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
end
But unfortunately it remains on the basic configuration ...
Thanking you in advance for the time you can give me.
BoudSTER
When I go to localhost:4567 in my browser, even after the rails server did it's thing, my chrom status is "waiting for..." .
It takes upwards of 30 seconds to reload a single page. All other web browsing works fine, and the Rails server is working fine. It's just the browser page load that takes for ever.
I even tried disabling forwarded_posrt and browsing right inside the vm... no luck: all requests to localhost take for ever.
Here is my vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.network :forwarded_port, guest: 3000, host: 4567
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "8"]
vb.customize ["modifyvm", :id, "--vram", "10"]
end
end
My host computer is running Ubuntu 13.04. Using virtualbox.
First I'd recommend using a different base box if you really need to customize the VM. Last time I tried using that box the VirtualBox customizations (vb.customize on your Vagrantfile) were not being applied correctly. You can double check that by installing the htop package and look into how many CPUs and memory it displays.
Another thing you might try is enabling NFS shared folders for your project root, check out this link for some numbers and in case you are willing to try it out, just add config.vm.synced_folder '.', '/vagrant', id: "vagrant-root", nfs: true to your Vagrantfile
Hope it helps :)
a) I'm a ruby in rails beginner developer, and I use windows 7 machine as developement environment...
b) With VirtualBox I just installed, inside the Windows 7 "host", a Linux ubuntu sever "guest", just to run the rails DEVELOPMENT environment ALSO in the linux machine.
c) To do that I configured a virtualbox SHARED FOLDER:
let say I have this shared folder on the host machine (window):
c:\rails\esamiAnatomia
and mounted it on the linux embedded server:
/home/solyaris/host/esamianatomia
d) In this exptended "developement environment" I would like to edit source files with my preferred visual editor on windows (sublime text) and run rails server on linux.
The problem concern database.yml configuration file:
/home/solyaris/host/esamianatomia/config/database.yml
because on Windows I have a database (postgresql) responding port 5433, with specific username/password
but in linux database respond to port 5432, etc.
Questions:
1) It's that "arcgitectural solution ok ? (I mean: developing/editing from a windows 7 host, but running rails server of the linux guest server);
2) There is a way to change/configure database.yml on the fly (I mean: using two different database.yml files: one for the linux machine and anotherone for the window machine) ?
thanks a lot
giorgio
You can technically accomplish 2 if you're not afraid to play around with the guts of Rails. As with any solution that has you accessing internal rails components this may stop working at any time, but fortunately this part of the API is not likely to change often, if ever. Still, use this at your own risk.
Here's how I do it on my projects. First modify your application as follows:
# config/application.rb:
# After require 'rails/all'
require_relative 'db_override'
Then create this new file:
# config/db_override.rb:
case Socket.gethostname
when 'host1'
$db_config = 'config/host1_database.yml'
when 'host2'
$db_config = 'config/host2_database.yml'
else
$db_config = nil # Use the default config/database.yml
end
if $db_config
class DBConfigSelect < Rails::Railtie
initializer "db_config_select", before: "active_record.initialize_database" do
puts "Using custom DB configuration: #{$db_config}"
# Get the existing path configuration
cur_paths = Rails.application.config.paths['config/database'].instance_variable_get :#paths
# Override the default config sources
cur_paths.shift
cur_paths.push $db_config
end
end
end
What you are describing is pretty much the setup that Vagrant is offering, so yeah, you are doing fine, everyone else is also doing it but they didn't set it up themselves (and by that probably get some really nice addons as well, you should take a look at Vagrant).
For your second question: no. Not on the fly. Rails loads the database.yml end then connects to the database with that. When you change it while your Rails server is running, the changes won't get noticed. What you can do however is setup a new environment for your two different machines. Then you can switch between the different environments and depending on the environment, one or the other database gets accessed.
I'm running rails on a nfs shared folder in a vagrant box. While the server (thin/webrick) is running I'm editing files in my host. But I have to keep stopping and restarting the application server to see changes reflected in the webapp. Is this normal behaviour?
I go this issue on Vagrant box synchronising my folder with NFS.
I made a change in my application development configuration file (config/environments/development.rb), just adding this line config.reload_classes_only_on_change = false and it works.
Ensure that you have this config.cache_classes = false as well, I had it by default when I setup rails application (using version 4.1.5), because where I found that workaround (http://edgeguides.rubyonrails.org/configuring.html) says that config.reload_classes_only_on_chage = false is ignored if config.cache_classes is true
Another solution is use vagrant Rsync synchronise mechanism, which is available from version 1.5 and have some benefits, but for me it doesn't work because I run out of space if I have to make a copy of my workspace on each virtual machine that I have.