vm-watcher 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/vm-watcher +7 -0
- data/lib/vm-watcher.rb +99 -0
- data/vm-watcher.gemspec +19 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 David Calavera
|
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,35 @@
|
|
1
|
+
# Vm::Watcher
|
2
|
+
|
3
|
+
Continuous VM provisioning.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Or install it yourself as:
|
8
|
+
|
9
|
+
$ gem install vm-watcher
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
1. Set up a VM using Vagrant.
|
14
|
+
2. Write your `script/provision` script, for instance to use chef-solo:
|
15
|
+
|
16
|
+
chef-solo -j dna.json -c solo.rb
|
17
|
+
|
18
|
+
3. Run `vm-watcher` from the terminal. It executes the provisioning script
|
19
|
+
inside the VM every time one of the files change.
|
20
|
+
|
21
|
+
There a several options that you can modify:
|
22
|
+
|
23
|
+
```
|
24
|
+
--watch: pattern that matches the files to watch, `Dir.pwd/**/*` by default.
|
25
|
+
--script: script to execute when one of those files change, `script/provision` by default.
|
26
|
+
--interval: sleep time before each check, 1 sec by default.
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/vm-watcher
ADDED
data/lib/vm-watcher.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
module Vm
|
2
|
+
module Watcher
|
3
|
+
require 'observer'
|
4
|
+
require 'optparse'
|
5
|
+
require 'vagrant'
|
6
|
+
require 'vagrant/ui'
|
7
|
+
|
8
|
+
class VmObserver
|
9
|
+
def initialize(observable, script)
|
10
|
+
observable.add_observer(self, :provision)
|
11
|
+
|
12
|
+
@script = script
|
13
|
+
|
14
|
+
@vagrant = Vagrant::Environment.new(:ui_class => Vagrant::UI::Basic)
|
15
|
+
@vagrant.cli('up', '--no-provision')
|
16
|
+
@vagrant.primary_vm.channel.ready?
|
17
|
+
end
|
18
|
+
|
19
|
+
def provision
|
20
|
+
@vagrant.primary_vm.channel.execute(@script, false) do |type, data|
|
21
|
+
@vagrant.primary_vm.ui.info(data.to_s, :prefix => false, :new_line => false, :channel => :out)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class VmWatcher
|
27
|
+
include Observable
|
28
|
+
|
29
|
+
def initialize(options = {})
|
30
|
+
@last_mtime = @last_ctime = Time.now
|
31
|
+
@watch = options[:watch]
|
32
|
+
@sleep_interval = options[:interval]
|
33
|
+
end
|
34
|
+
|
35
|
+
def watch
|
36
|
+
files = Dir.glob(@watch).map {|f| Pathname(f).expand_path }
|
37
|
+
if files.empty?
|
38
|
+
abort "No files to watch under #{@watch}"
|
39
|
+
end
|
40
|
+
|
41
|
+
loop do
|
42
|
+
last_modified = files.max {|a, b| a.mtime <=> b.mtime}
|
43
|
+
|
44
|
+
if last_modified.mtime > @last_mtime
|
45
|
+
notify(last_modified)
|
46
|
+
else
|
47
|
+
last_changed = files.max {|a, b| a.ctime <=> b.ctime}
|
48
|
+
notify(last_changed) if last_changed.ctime > @last_ctime
|
49
|
+
end
|
50
|
+
|
51
|
+
sleep @sleep_interval
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def notify(modified)
|
56
|
+
@last_mtime, @last_ctime = modified.mtime, modified.ctime
|
57
|
+
changed
|
58
|
+
notify_observers
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.init(args)
|
63
|
+
options = parse(args)
|
64
|
+
|
65
|
+
watcher = VmWatcher.new(options)
|
66
|
+
observer = VmObserver.new(watcher, options[:script])
|
67
|
+
watcher.watch
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.parse(args)
|
71
|
+
options = {
|
72
|
+
:script => 'script/provision',
|
73
|
+
:watch => "#{Dir.pwd}/**/*",
|
74
|
+
:interval => 1
|
75
|
+
}
|
76
|
+
|
77
|
+
OptionParser.new do |opts|
|
78
|
+
opts.banner = "Usage: vm-watcher [options]"
|
79
|
+
|
80
|
+
opts.separator ""
|
81
|
+
opts.separator "Specific options:"
|
82
|
+
|
83
|
+
opts.on('-s', '--script SCRIPT', 'Path to the script to call') do |script|
|
84
|
+
options[:script] = script
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.on('-w', '--watch PATTERN', 'Files pattern to watch') do |pattern|
|
88
|
+
options[:watch] = pattern
|
89
|
+
end
|
90
|
+
|
91
|
+
opts.on('-i', '--interval SECONDS', 'Sleep time interval before checking modifications') do |interval|
|
92
|
+
options[:interval] = interval.to_i
|
93
|
+
end
|
94
|
+
end.parse!(args)
|
95
|
+
|
96
|
+
options
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/vm-watcher.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["David Calavera"]
|
5
|
+
gem.email = ["david.calavera@gmail.com"]
|
6
|
+
gem.description = "Continuous VM provisioning"
|
7
|
+
gem.summary = gem.description
|
8
|
+
gem.homepage = "http://github.com/calavera/vm-watcher"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "vm-watcher"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = '0.1.0'
|
16
|
+
|
17
|
+
gem.add_runtime_dependency('vagrant')
|
18
|
+
gem.add_development_dependency('rake')
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vm-watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Calavera
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vagrant
|
16
|
+
requirement: &70183756994460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70183756994460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70183756993140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70183756993140
|
36
|
+
description: Continuous VM provisioning
|
37
|
+
email:
|
38
|
+
- david.calavera@gmail.com
|
39
|
+
executables:
|
40
|
+
- vm-watcher
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- bin/vm-watcher
|
50
|
+
- lib/vm-watcher.rb
|
51
|
+
- vm-watcher.gemspec
|
52
|
+
homepage: http://github.com/calavera/vm-watcher
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
hash: 1285861561528317551
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: 1285861561528317551
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.11
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Continuous VM provisioning
|
82
|
+
test_files: []
|