vagrant-notify-forwarder 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d3036da0c84c970b025b499e3db1f161b4834f8a
4
+ data.tar.gz: 8716f2cea05962cdb24329a4c95163bd52c3bd96
5
+ SHA512:
6
+ metadata.gz: d52251ae022a89c51f319b8f6db84aa5b2fe7b3a0e0c4aec6a77f52c1a18b6c7bb01d7ee976abcfd90b4688fe0cd8bedfe3f0d552862157b160f9d4961eeef7e
7
+ data.tar.gz: 25705479032b9e2db1e5aa33e2e9a0c7a8f2fb9f5eb5327d4abe5aec0cf6a8a839cf6b90ab9899ce415ec04fa4814eeda8d13bf74d57b532209e919eebb5b3d7
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ Vagrantfile
24
+ /.vagrant
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-notify-forwarder", path: "."
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 mhallin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Vagrant file system notification forwarder plugin
2
+
3
+ A vagrant plugin that uses [notify-forwarder](https://github.com/mhallin/notify-forwarder) to
4
+ forward file system events from the host to the guest automatically on all shared folders.
5
+
6
+ This is useful for auto reloading file systems that rebuild when files change. Normally, they have
7
+ to use CPU intensive polling when watching shared folders. This plugin makes them able to use
8
+ inotify or similar for improved performance and reduced CPU usage.
9
+
10
+ ## Installation and usage
11
+
12
+ ```terminal
13
+ $ vagrant plugin install vagrant-notify-forwarder
14
+ $ vagrant reload
15
+ ```
16
+
17
+ By default, this sets up UDP port 29324 for port forwarding. If you're already using this port, or
18
+ if you want to change it, add the following line to your `Vagrantfile`:
19
+
20
+ ```ruby
21
+ config.notify_forwarder.port = 22020 # Or your port number
22
+ ```
23
+
24
+ The server and guest binaries will be automatically downloaded from the notify-forwarder repo's
25
+ releases and verified with SHA256.
26
+
27
+ ## Supported operating systems
28
+
29
+ To conserve size and dependencies, the plugin downloads binaries for supported platforms. This
30
+ plugin supports the same host/guest platforms as `notify-forwarder` itself:
31
+
32
+ * FreeBSD 64 bit as guest,
33
+ * Linux 64 bit as host and guest, and
34
+ * Mac OS X 64 bit as host and guest.
35
+
36
+ If you're running an unsupported host or guest and want to disable this plugin for a specific
37
+ machine, add the following line to your `Vagrantfile`:
38
+
39
+ ```ruby
40
+ config.notify_forwarder.enable = false
41
+ ```
@@ -0,0 +1,39 @@
1
+ require "vagrant"
2
+
3
+ module VagrantNotifyForwarderPlugin
4
+
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "vagrant-notify-forwarder"
7
+ description "Wrapper around the notify-forwarder file system event forwarder"
8
+
9
+ register_boot_hooks = lambda do |hook|
10
+ require_relative "vagrant-notify-forwarder/action"
11
+
12
+ hook.after Vagrant::Action::Builtin::Provision,
13
+ VagrantNotifyForwarderPlugin::Action::StartHostForwarder
14
+ hook.after VagrantNotifyForwarderPlugin::Action::StartHostForwarder,
15
+ VagrantNotifyForwarderPlugin::Action::StartClientForwarder
16
+ end
17
+
18
+ register_halt_hooks = lambda do |hook|
19
+ require_relative "vagrant-notify-forwarder/action"
20
+
21
+ hook.before Vagrant::Action::Builtin::GracefulHalt,
22
+ VagrantNotifyForwarderPlugin::Action::StopHostForwarder
23
+ end
24
+
25
+ config "notify_forwarder" do
26
+ require_relative "vagrant-notify-forwarder/config"
27
+
28
+ VagrantNotifyForwarderPlugin::Config::Config
29
+ end
30
+
31
+ action_hook :start_notify_forwarder, :machine_action_up, &register_boot_hooks
32
+ action_hook :start_notify_forwarder, :machine_action_reload, &register_boot_hooks
33
+
34
+ action_hook :stop_notify_forwarder, :machine_action_halt, &register_halt_hooks
35
+ action_hook :stop_notify_forwarder, :machine_action_reload, &register_halt_hooks
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,183 @@
1
+ module VagrantNotifyForwarderPlugin
2
+
3
+ module Action
4
+
5
+ class Utils
6
+ @@OS_NAMES = {
7
+ "Linux" => :linux,
8
+ "Darwin" => :darwin,
9
+ "FreeBSD" => :freebsd,
10
+ }
11
+
12
+ @@HARDWARE_NAMES = {
13
+ "x86_64" => :x86_64,
14
+ }
15
+
16
+ def self.parse_os_name(data)
17
+ @@OS_NAMES[data.strip] or :unsupported
18
+ end
19
+
20
+ def self.parse_hardware_name(data)
21
+ @@HARDWARE_NAMES[data.strip] or :unsupported
22
+ end
23
+
24
+ def self.host_pidfile(env)
25
+ env[:machine].data_dir.join('notify_watcher_host_pid')
26
+ end
27
+
28
+ def self.ensure_binary_downloaded(env, os, hardware)
29
+ download_urls = {
30
+ [:linux, :x86_64] => ['https://github.com/mhallin/notify-forwarder/releases/download/release/v0.1.0/notify-forwarder_linux_x64',
31
+ '7d14996963f45d9b1c85e78d0aa0c94371d585d0ccabae482c2ef5968417a7f0'],
32
+ [:darwin, :x86_64] => ['https://github.com/mhallin/notify-forwarder/releases/download/release/v0.1.0/notify-forwarder_osx_x64',
33
+ 'd8ad61d9b70394b55bc22c94771ca6f88f0f51868617c3b2c55654ebde866c23'],
34
+ [:freebsd, :x86_64] => ['https://github.com/mhallin/notify-forwarder/releases/download/release/v0.1.0/notify-forwarder_freebsd_x64',
35
+ '2df0884958b2469dd7113660cf2de01e9e5dd8fcad0213bff3335833e6668f84'],
36
+ }
37
+
38
+ url, sha256sum = download_urls[[os, hardware]]
39
+ path = env[:tmp_path].join File.basename(url)
40
+ should_download = true
41
+
42
+ if File.exists? path
43
+ digest = Digest::SHA256.file(path).hexdigest
44
+
45
+ if digest == sha256sum
46
+ should_download = false
47
+ end
48
+ end
49
+
50
+ if should_download
51
+ env[:ui].info 'Notify-forwarder: Downloading client'
52
+ downloader = Vagrant::Util::Downloader.new url, path
53
+ downloader.download!
54
+ end
55
+
56
+ File.chmod(0755, path)
57
+
58
+ path
59
+ end
60
+ end
61
+
62
+ class StartHostForwarder
63
+ def initialize(app, env)
64
+ @app = app
65
+ end
66
+
67
+ def ensure_binary_downloaded(env)
68
+ os = Utils.parse_os_name `uname -s`
69
+ hardware = Utils.parse_hardware_name `uname -m`
70
+
71
+ env[:ui].error 'Notify-forwarder: Unsupported host operating system' if os == :unsupported
72
+ env[:ui].error 'Notify-forwarder: Unsupported host hardware' if hardware == :unsupported
73
+
74
+ if os != :unsupported and hardware != :unsupported
75
+ Utils.ensure_binary_downloaded env, os, hardware
76
+ end
77
+ end
78
+
79
+ def start_watcher(env, command)
80
+ pid = Process.spawn command
81
+ Process.detach(pid)
82
+
83
+ pidfile = Utils.host_pidfile env
84
+ pidfile.open('w+') do |f|
85
+ f.write(pid)
86
+ end
87
+ end
88
+
89
+ def call(env)
90
+ if env[:machine].config.notify_forwarder.enable
91
+ port = env[:machine].config.notify_forwarder.port
92
+ env[:machine].config.vm.network :forwarded_port, host: port, guest: port, protocol: 'udp'
93
+ end
94
+
95
+ @app.call env
96
+
97
+ if env[:machine].config.notify_forwarder.enable
98
+ path = ensure_binary_downloaded env
99
+ return unless path
100
+
101
+ args = "watch -c 127.0.0.1:#{port}"
102
+
103
+ env[:machine].config.vm.synced_folders.each do |id, options|
104
+ unless options[:disabled]
105
+ hostpath = File.absolute_path(options[:hostpath])
106
+ guestpath = options[:guestpath]
107
+
108
+ args += " #{hostpath} #{guestpath}"
109
+ end
110
+ end
111
+
112
+ start_watcher env, "#{path} #{args}"
113
+ end
114
+ end
115
+ end
116
+
117
+ class StopHostForwarder
118
+ def initialize(app, env)
119
+ @app = app
120
+ end
121
+
122
+ def call(env)
123
+ @app.call env
124
+
125
+ return unless env[:machine].config.notify_forwarder.enable
126
+
127
+ pidfile = Utils.host_pidfile env
128
+ if File.exists? pidfile
129
+ pidfile.open('r') do |f|
130
+ pid = f.read.to_i
131
+
132
+ begin
133
+ Process.kill 'TERM', pid
134
+ rescue Errno::ESRCH
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ class StartClientForwarder
142
+ def initialize(app, env)
143
+ @app = app
144
+ end
145
+
146
+ def ensure_binary_downloaded(env)
147
+ os = :unsupported
148
+ hardware = :unsupported
149
+
150
+ env[:machine].communicate.execute('uname -s') do |type, data|
151
+ os = Utils.parse_os_name data if type == :stdout
152
+ end
153
+
154
+ env[:machine].communicate.execute('uname -m') do |type, data|
155
+ hardware = Utils.parse_hardware_name data if type == :stdout
156
+ end
157
+
158
+ env[:ui].error 'Notify-forwarder: Unsupported client operating system' if os == :unsupported
159
+ env[:ui].error 'Notify-forwarder: Unsupported client hardware' if hardware == :unsupported
160
+
161
+ if os != :unsupported and hardware != :unsupported
162
+ Utils.ensure_binary_downloaded env, os, hardware
163
+ end
164
+ end
165
+
166
+ def call(env)
167
+ @app.call env
168
+
169
+ return unless env[:machine].config.notify_forwarder.enable
170
+
171
+ path = ensure_binary_downloaded env
172
+ return unless path
173
+
174
+ port = env[:machine].config.notify_forwarder.port
175
+
176
+ env[:machine].communicate.upload(path, "/tmp/notify-forwarder")
177
+ env[:machine].communicate.execute("nohup /tmp/notify-forwarder receive -p #{port} &")
178
+ end
179
+ end
180
+
181
+ end
182
+
183
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantNotifyForwarderPlugin
2
+ module Config
3
+
4
+ class Config < Vagrant.plugin("2", :config)
5
+ attr_accessor :port
6
+ attr_accessor :enable
7
+
8
+ def initialize
9
+ @port = UNSET_VALUE
10
+ @enable = UNSET_VALUE
11
+ end
12
+
13
+ def finalize!
14
+ @port = 29324 if @port == UNSET_VALUE
15
+ @enable = true if @enable == UNSET_VALUE
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantNotifyForwarderPlugin
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-notify-forwarder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-notify-forwarder"
8
+ spec.version = VagrantNotifyForwarderPlugin::VERSION
9
+ spec.authors = ["Magnus Hallin"]
10
+ spec.email = ["mhallin@gmail.com"]
11
+ spec.summary = "A vagrant plugin that forwards file system events from the host to the guest"
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/mhallin/vagrant-notify-forwarder"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.require_paths = ["lib"]
18
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-notify-forwarder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Magnus Hallin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A vagrant plugin that forwards file system events from the host to the
14
+ guest
15
+ email:
16
+ - mhallin@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - lib/vagrant-notify-forwarder.rb
26
+ - lib/vagrant-notify-forwarder/action.rb
27
+ - lib/vagrant-notify-forwarder/config.rb
28
+ - lib/vagrant-notify-forwarder/version.rb
29
+ - vagrant-notify-forwarder.gemspec
30
+ homepage: https://github.com/mhallin/vagrant-notify-forwarder
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.0.14
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: A vagrant plugin that forwards file system events from the host to the guest
54
+ test_files: []