vagrant-listen-server 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cfeb1cec6dac82766c551f2f274d37e3c0de392
4
+ data.tar.gz: 834d63a319938c3c5421ec444156b827f510a6d1
5
+ SHA512:
6
+ metadata.gz: 17bec5357fa7ea92af00b9954c61c9034ef08d3db310a43524d5f0f789d02c0dee2fe12ce8ad662cb8f405314861dad027f0207ccf5a20eec69c89018c2449b8
7
+ data.tar.gz: a3c4f81f2255169a77bfc4c139a8052c538cb74664510664114d33d586a3c1021c829ff7e617abe185f169bfcd2ae356c5cfd25d3045061a3961e83b6984ba46
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,12 @@
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-listen-server', path: '.'
9
+ gem 'listen'
10
+ gem 'celluloid'
11
+ gem 'celluloid-io'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 David Kelso
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,94 @@
1
+ # vagrant-listen-server
2
+
3
+ Forward filesystem events from a host to a client
4
+
5
+
6
+ Vagrant's shared folders don't pass file modification notifications to the
7
+ guest. That means editing files locally won't trigger off inotify file events,
8
+ which means any build / test / servers that need to reload on change have to
9
+ poll for changes.
10
+
11
+ If you're using virtualbox, vboxsf performance really really sucks. Hard links
12
+ are impossible. Statting takes forever.
13
+ * http://mitchellh.com/comparing-filesystem-performance-in-virtual-machines
14
+
15
+ Since polling implementations will probably rely on statting the file in some
16
+ way, this creates a pretty awful experience.
17
+
18
+
19
+ The answer - forwarding filesystem events
20
+
21
+ The listen gem is already used by vagrant, (as part of rsync-auto) and allows forwarding of filesystem events over TCP.
22
+
23
+ # The listen gem, as used by rsync-auto, is apparently a bit of a resource hog
24
+ # because it stats all files before sending events.
25
+
26
+
27
+ ## Clients
28
+
29
+ The main reason I developed this was to allow filesystem events to be pushed
30
+ to a broccoli build pipeline.
31
+
32
+ Ideally, you can subscribe to the file changes and trigger builds / whatever in
33
+ your app
34
+
35
+ You can also write a simple server that touches all files on the guest, however
36
+ you'll have to be aware of loops created if filesystem notifications are passed
37
+ back from the guest to the host.
38
+
39
+
40
+
41
+ ## Usage
42
+
43
+ Install the plugin:
44
+
45
+ `vagrant plugin install vagrant-listen-server`
46
+
47
+ Then in your Vagrantfile:
48
+
49
+ ```ruby
50
+ if Vagrant.has_plugin? 'vagrant-listen-server'
51
+ config.listen_server.ip = '172.168.172.16'
52
+ config.listen_server.port = 4000
53
+ config.listen_server.folders = '../beyondpricing/client'
54
+ config.listen_server.pid_file = '/tmp/beyond.listen.pid'
55
+ end
56
+ ```
57
+
58
+
59
+ ## Other options
60
+
61
+ * rsync-auto
62
+ # * http://docs.vagrantup.com/v2/cli/rsync-auto.html
63
+ # Filesystem is shared using rsync-auto protocol instead of vboxsf
64
+ # Pros: Pushes files onto guest, so guest can fire native events
65
+ # Cons: Slow, apparently a resource hog.
66
+
67
+
68
+ * rsync-mirror
69
+ https://github.com/ingenerator/vagrant-mirror/
70
+ Looks good, but super outdated.
71
+
72
+
73
+
74
+
75
+ ## Development
76
+
77
+ To develop locally
78
+ ```
79
+ gem build vagrant-listen-server.gemspec
80
+ vagrant plugin install vagrant-listen-server-0.0.1.gem
81
+ ```
82
+
83
+ Other good vagrant plugins used for reference:
84
+ * https://github.com/mitchellh/vagrant-aws/blob/master/Rakefile
85
+ * vagrant-ls - http://www.noppanit.com/create-simple-vagrant-plugin/
86
+
87
+
88
+ ## TODO:
89
+
90
+ Listen maybe is a bit of a resource hog:
91
+ * https://github.com/mitchellh/vagrant/issues/3249
92
+
93
+ There might be some better, native implementations that make this faster. e.g.
94
+ * https://fsnotify.org/
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,10 @@
1
+ require 'vagrant-listen-server/version'
2
+ require 'vagrant-listen-server/plugin'
3
+
4
+ module VagrantPlugins
5
+ module ListenServer
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,92 @@
1
+ require 'celluloid'
2
+ require 'listen'
3
+
4
+ module VagrantPlugins
5
+ module ListenServer
6
+ module Action
7
+ class StartServer
8
+ def initialize(app, env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ @env = env
14
+ @ui = env[:ui]
15
+ @machine = env[:machine]
16
+
17
+ config = @machine.config.listen_server
18
+ folders = config.folders
19
+ host = "#{config.ip}:#{config.port}"
20
+
21
+ @ui.info "Starting listen server - #{host}"
22
+
23
+ # Check whether the daemon is already running.
24
+ if File.exists? config.pid_file
25
+ pid = File.read config.pid_file
26
+ begin
27
+ Process.getpgid pid.to_i
28
+ @ui.info 'Warning - listen server already running'
29
+ return @app.call(env)
30
+ rescue Errno::ESRCH
31
+ @ui.info 'Warning - stale PID file'
32
+ end
33
+ end
34
+
35
+ out = @app.call(env)
36
+
37
+ # Vagrant-notify uses fork here, but that doesn't work on windows:
38
+ # https://github.com/fgrehm/vagrant-notify/blob/master/lib/vagrant-notify/server.rb
39
+ # Only real option is to switch to Process.spawn? I need a windows
40
+ # machine to test it out on...
41
+ pid = fork do
42
+ $0 = "vagrant-listen-server - #{@machine.name}"
43
+ listener = Listen.to folders, forward_to: host do |modified, added, removed|
44
+ File.open('/tmp/listen.txt', 'a+') do |f|
45
+ f.puts 'listen fired', modified, added, removed
46
+ end
47
+ end
48
+
49
+ begin
50
+ listener.start
51
+ rescue Errno::EADDRNOTAVAIL
52
+ @ui.info "Can't start server - Port in use"
53
+ exit
54
+ end
55
+ sleep
56
+ end
57
+
58
+ Process.detach pid
59
+ File.write config.pid_file, pid
60
+ @ui.info "Listen server started on PID #{pid}"
61
+
62
+ out
63
+ end
64
+ end
65
+
66
+ class KillServer
67
+ def initialize(app, env)
68
+ @app = app
69
+ end
70
+
71
+ def call(env)
72
+ @ui = env[:ui]
73
+ config = env[:machine].config.listen_server
74
+ @ui.info 'Killing listen server'
75
+ if File.exists? config.pid_file
76
+ pid = File.read config.pid_file
77
+ begin
78
+ Process.kill 'INT', pid.to_i
79
+ rescue Errno::ESRCH
80
+ @ui.info 'Stale PID file - no server found'
81
+ end
82
+ File.delete config.pid_file
83
+ else
84
+ @ui.info 'No listen server found'
85
+ end
86
+
87
+ @app.call(env)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantPlugins
2
+ module ListenServer
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :ip
5
+ attr_accessor :port
6
+ attr_accessor :folders
7
+ attr_accessor :pid_file
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'action'
2
+
3
+ module VagrantPlugins
4
+ module ListenServer
5
+ class Plugin < Vagrant.plugin('2')
6
+ name 'ListenServer'
7
+
8
+ description <<-DESC
9
+ Start a Listen server to forward filesystem events to the client VM.
10
+ DESC
11
+
12
+ config(:listen_server) do
13
+ require_relative 'config'
14
+ Config
15
+ end
16
+
17
+ action_hook(:listen_server, :machine_action_up) do |hook|
18
+ hook.append(Action::StartServer)
19
+ end
20
+
21
+ action_hook(:listen_server, :machine_action_halt) do |hook|
22
+ hook.append(Action::KillServer)
23
+ end
24
+
25
+ action_hook(:listen_server, :machine_action_suspend) do |hook|
26
+ hook.append(Action::KillServer)
27
+ end
28
+
29
+ action_hook(:listen_server, :machine_action_destroy) do |hook|
30
+ hook.append(Action::KillServer)
31
+ end
32
+
33
+ action_hook(:listen_server, :machine_action_reload) do |hook|
34
+ hook.append(Action::StartServer)
35
+ end
36
+
37
+ action_hook(:listen_server, :machine_action_resume) do |hook|
38
+ hook.append(Action::StartServer)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module ListenServer
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-listen-server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vagrant-listen-server'
8
+ spec.version = VagrantPlugins::ListenServer::VERSION
9
+ spec.authors = ['David Kelso']
10
+ spec.email = ['david@kelso.id.au']
11
+ spec.summary = %q{Guard / Listen TCP server to publich filesystem events to guests.}
12
+ spec.homepage = 'https://github.com/zaius/vagrant-listen-server'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'celluloid', '~> 0.16'
21
+ spec.add_runtime_dependency 'celluloid-io', '~> 0.16', '>= 0.16.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-listen-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - David Kelso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: celluloid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: celluloid-io
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.16'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.16.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.16'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.16.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description:
76
+ email:
77
+ - david@kelso.id.au
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - lib/vagrant-listen-server.rb
88
+ - lib/vagrant-listen-server/action.rb
89
+ - lib/vagrant-listen-server/config.rb
90
+ - lib/vagrant-listen-server/plugin.rb
91
+ - lib/vagrant-listen-server/version.rb
92
+ - vagrant-listen-server.gemspec
93
+ homepage: https://github.com/zaius/vagrant-listen-server
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Guard / Listen TCP server to publich filesystem events to guests.
117
+ test_files: []