Install a better Rsync watcher for Vagrant machines

Dec 20, 2016 Vagrant 中文版

Vagrant allows us to utilise Rsync to automatically sync files to Vagrant machines. However, the performance and stability of the built-in auto-sync mechanism are not perfect. Thus, this post goes into how to install and use a better Rsync watcher (vagrant-gatling-rsync) for your Vagrant machines under macOS.



Prerequisite

Luckily, Rsync is already installed in your Mac machine, but it might be a little bit out-of-date. If you like to use the latest version, you can use Homebrew to upgrade. To check the current version:

rsync --version


Install vagrant-gatling-rsync

Let’s install the plugin:

# List installed plugins
vagrant plugin list

# Install vagrant-gatling-rsync
vagrant plugin install vagrant-gatling-rsync


Enable Rsync and set the plugin for Vagrant machine

Open your Vagrant machine configuration (Vagrantfile), and then add below setting into it:

 ...

  # Enable Rsync
  config.vm.synced_folder "/path/to/local/folder", "/path/to/vm/folder",
    type: "rsync",
    rsync__exclude: [".git/", "*.swp"]

  # Configure vagrant-gatling-rsync
  if Vagrant.has_plugin?("vagrant-gatling-rsync")
    config.gatling.latency = 1.0
    config.gatling.time_format = "%H:%M:%S"
  end

  config.gatling.rsync_on_startup = true

 ...

To make it right, you have to specify two absolute paths for vm.synced_folder. In addition, you can exclude files or folders by setting rsync__exclude.

Start auto-sync

If you follow above steps and set config.gatling.rsync_on_startup = true, the auto-sync will automatically start when you running up the Vagrant machine, and it will also sync files once you make any changes.


You might also like:




If you have any suggestions, questions or even find some typos, feel free to contact me. Thank you! :)

zeckli.devforgalaxy@gmail.com   © 2015-2019 zeckli, thanks to Jekyll and GitHub.