Vagrant RSYNC-AUTO failing on OSX ~10.11

Upgraded to 1.8.4 of Vagrant this week to keep my local version up to date but when I ran rsync-auto as I normally did I came accross the following error:

rb-fsevent > 0.9.4 no longer supports OS X 10.6 through 10.8.

Please add the following to your Gemfile to avoid polling for changes:  
  require 'rbconfig'
  if RbConfig::CONFIG['target_os'] =~ /darwin(1[0-3])/i
    gem 'rb-fsevent', '<= 0.9.4'
  end
[Listen warning]:
  Listen will be polling for changes.Learn more at https://github.com/guard/listen#listen-adapters.
rb-fsevent > 0.9.4 no longer supports OS X 10.6 through 10.8.

Please add the following to your Gemfile to avoid polling for changes:  
  require 'rbconfig'
  if RbConfig::CONFIG['target_os'] =~ /darwin(1[0-3])/i
    gem 'rb-fsevent', '<= 0.9.4'
  end

Gee thanks for the detailed information to fix this ...

Having no idea what this "Gemfile" is that I should be editig I heading to Google. After some hair pulling I opted to rather to write my own quick watch script (which is a bit quicker as well as I'm only syncing the folder where the change happened).

First run:

vagrant ssh-config >>> ~/.ssh/conf  

If you have not already, then head over to ~/.ssh/conf with a text editor like nano or vi[m].

Edit the entry named Host default that Vagrant created to anything that you would like, in my case I'll keep it as Host default.

Now in your project file create the following file replaceing <vagrant-host-here> with your chosen name for the vagrant host (in my case default):

filename=$1  
PWD=$(pwd)  
parent_path=$( cd "$(dirname '$PWD')" ; pwd -P )  
target_dir=$(dirname ${filename#$parent_path})  
local_dir=$PWD$(echo $target_dir)/  
remote_dir=/vagrant$(echo $target_dir)  
rsync -azr --exclude=".git" --exclude="node_modules/" --delete --rsync-path="sudo rsync" ${local_dir} <vagrant-host-here>:${remote_dir}  

in my case I named it sync.sh. After which make sure the file is excutable using chdmod a+x sync.sh.

Now we need to execute this script and pass it the name of the changed file everytime we save something. To do this I used fswatch which can be installed using:

brew install fswatch  

which can then be run as such to start our syncing:

fswatch -r --exclude=".git" --exclude="node_modules/" --exclude="public/css" --exclude="public/js" $(pwd) | xargs -n1 ./sync.sh  

Test and enjoy, rsync will now be running when a file changes and will rsync only the folder that the file is in saving you some processing power.


Posted on 2016/06/28 by Johann du Toit

comments powered by Disqus