vagrant-notify 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +24 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -3
- data/LICENSE.txt +1 -1
- data/README.md +15 -4
- data/examples/README.md +16 -0
- data/examples/osx/notify-send_terminal-notifier +33 -0
- data/examples/windows/notify-send_growl_for_windows +36 -0
- data/files/notify-send.erb +5 -6
- data/lib/vagrant-notify/action/install_command.rb +6 -3
- data/lib/vagrant-notify/action/server_is_running.rb +9 -3
- data/lib/vagrant-notify/action/start_server.rb +26 -3
- data/lib/vagrant-notify/action/stop_server.rb +8 -1
- data/lib/vagrant-notify/action/windows/process_info.rb +23 -0
- data/lib/vagrant-notify/action.rb +17 -0
- data/lib/vagrant-notify/command.rb +66 -0
- data/lib/vagrant-notify/plugin.rb +13 -1
- data/lib/vagrant-notify/server.rb +29 -12
- data/lib/vagrant-notify/version.rb +1 -1
- data/lib/vagrant-notify.rb +0 -1
- data/spec/action/start_server_spec.rb +18 -12
- data/spec/action/stop_server_spec.rb +2 -1
- data/vagrant-notify.gemspec +2 -2
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3f06401113919234836bb523fe7c76febdde45b
|
4
|
+
data.tar.gz: f7cb2652a42a65b648adbfda7eb700e769a8d28b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f8ed1ad51e9de58df011dc50d5949d852fd852d19248f708558e119ee6f9a25ecd2895c0727671a3dbdb9913dd0650635febb1b8a65034cc3c359e73e4c92d
|
7
|
+
data.tar.gz: 809382012aaf777f192da1152bc360254d142f5b178540256b1f7e342781bfdd4dda55cf92cd32b36e8c767ed0a29ebcf5d893dec8d8feae311cacaffb0cbcc6
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,27 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
|
3
|
+
## [0.5.0](https://github.com/fgrehm/vagrant-notify/compare/v0.4.0...v0.5.0) (June 21, 2016)
|
4
|
+
|
5
|
+
IMPROVEMENTS
|
6
|
+
|
7
|
+
- Notification server runs as a daemon (fork() has been removed so it's compatible with Windows). [[GH-14]]
|
8
|
+
- Windows support (beta) [[GH-14]]
|
9
|
+
- Notification server is available from localhost.
|
10
|
+
- Notification server information is displayed each time vagrant is started and halted.
|
11
|
+
- New plugin command. Ability to view notification server status, and ability for manual restart. [CLI](https://gist.github.com/alpha01/9b81caca694a2735e658f978c41600b5)
|
12
|
+
- New notify-send example scripts for OS X and Windows
|
13
|
+
|
14
|
+
BUG FIXES
|
15
|
+
|
16
|
+
- `vagrant suspend/resume` stops/starts notification server respectively. [[GH-18]]
|
17
|
+
- Plugin causes VM boot to fail. [[GH-22]]
|
18
|
+
|
19
|
+
[GH-14]:https://github.com/fgrehm/vagrant-notify/issues/14
|
20
|
+
[GH-18]:https://github.com/fgrehm/vagrant-notify/issues/18
|
21
|
+
[GH-22]:https://github.com/fgrehm/vagrant-notify/pull/22
|
22
|
+
|
23
|
+
|
24
|
+
## [0.4.0](https://github.com/fgrehm/vagrant-notify/compare/v0.3.0...v0.4.0) (Feb 26, 2014)
|
2
25
|
|
3
26
|
IMPROVEMENTS
|
4
27
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git://github.com/fgrehm/vagrant-lxc.git
|
3
|
-
revision:
|
3
|
+
revision: 4a84d95ff26bf2d887b127765a9ae404899734f9
|
4
4
|
specs:
|
5
|
-
vagrant-lxc (0.
|
5
|
+
vagrant-lxc (0.8.1.dev)
|
6
6
|
|
7
7
|
GIT
|
8
8
|
remote: git://github.com/mitchellh/vagrant.git
|
@@ -19,7 +19,7 @@ GIT
|
|
19
19
|
PATH
|
20
20
|
remote: .
|
21
21
|
specs:
|
22
|
-
vagrant-notify (0.
|
22
|
+
vagrant-notify (0.5.0)
|
23
23
|
|
24
24
|
GEM
|
25
25
|
remote: https://rubygems.org/
|
@@ -51,6 +51,7 @@ GEM
|
|
51
51
|
net-scp (1.1.2)
|
52
52
|
net-ssh (>= 2.6.5)
|
53
53
|
net-ssh (2.7.0)
|
54
|
+
ocra (1.3.6)
|
54
55
|
pry (0.9.12.2)
|
55
56
|
coderay (~> 1.0.5)
|
56
57
|
method_source (~> 0.8)
|
@@ -80,6 +81,7 @@ PLATFORMS
|
|
80
81
|
DEPENDENCIES
|
81
82
|
guard
|
82
83
|
guard-rspec
|
84
|
+
ocra
|
83
85
|
rake
|
84
86
|
rb-inotify
|
85
87
|
rspec (~> 2.13.0)
|
@@ -87,3 +89,6 @@ DEPENDENCIES
|
|
87
89
|
vagrant!
|
88
90
|
vagrant-lxc!
|
89
91
|
vagrant-notify!
|
92
|
+
|
93
|
+
BUNDLED WITH
|
94
|
+
1.10.6
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/fgrehm/vagrant-notify.png)](https://travis-ci.org/fgrehm/vagrant-notify)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/vagrant-notify.png)](http://badge.fury.io/rb/vagrant-notify)
|
5
|
-
[![Gittip](http://img.shields.io/gittip/fgrehm.svg)](https://www.gittip.com/fgrehm/)
|
6
5
|
|
7
6
|
A Vagrant plugin that forwards `notify-send` from guest to host machine and
|
8
7
|
notifies provisioning status. [See it in action](#demo)
|
@@ -30,8 +29,8 @@ command.
|
|
30
29
|
### Provisioning notification
|
31
30
|
|
32
31
|
Apart from redirecting `notify-send` from the guest VM to the host, whenever
|
33
|
-
a Vagrant provisioner completes running you'll also receive
|
34
|
-
like:
|
32
|
+
a Vagrant 1.4+ provisioner starts or completes running you'll also receive
|
33
|
+
notifications like:
|
35
34
|
|
36
35
|
![provisioning](http://i.imgur.com/DgKjDgr.png)
|
37
36
|
|
@@ -56,14 +55,26 @@ A (too) primitive script integrating with Growl:
|
|
56
55
|
growlnotify -t "Vagrant VM" -m "$*"
|
57
56
|
```
|
58
57
|
|
58
|
+
See example [scripts](https://github.com/fgrehm/vagrant-notify/tree/master/examples).
|
59
|
+
|
60
|
+
### Windows (beta)
|
61
|
+
|
62
|
+
You can use the freeware application [notify-send for Windows](http://vaskovsky.net/notify-send/), make sure the notify-send binary is available on `Path`.
|
63
|
+
|
64
|
+
See example [scripts](https://github.com/fgrehm/vagrant-notify/tree/master/examples).
|
65
|
+
|
66
|
+
|
59
67
|
## Demo
|
60
68
|
|
61
69
|
![Demo](http://i.imgur.com/tzOLvGY.gif)
|
70
|
+
![Demo OS X](http://i.imgur.com/216NIlf.gif)
|
71
|
+
![Demo Windows](http://i.imgur.com/cJYqX4y.gif)
|
62
72
|
|
63
73
|
|
64
74
|
## Known issues
|
65
75
|
|
66
|
-
* `vagrant
|
76
|
+
* `vagrant destroy` on a running VM will not stop the notification server.
|
77
|
+
* On rare occasions the notification server may stop receiving notifications if the host is suspended/hibernates. The notification server may need to be manually restarted if that's the case. `vagrant notify --restart`
|
67
78
|
|
68
79
|
|
69
80
|
## Contributing
|
data/examples/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Example notify-send wrapper scripts
|
2
|
+
|
3
|
+
## OS X
|
4
|
+
|
5
|
+
* [terminal-notifier](https://github.com/alloy/terminal-notifier) [wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/notify-send_terminal-notifier)
|
6
|
+
|
7
|
+
|
8
|
+
## Windows
|
9
|
+
|
10
|
+
* [Growl for Windows](http://www.growlforwindows.com/gfw/default.aspx) [wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/windows/notify-send_growl_for_windows)
|
11
|
+
|
12
|
+
**IMPORTANT:** `notify-send` wrapper script has to be binary executable. Also as with `notify-send`, `growlnotify.exe` needs to be is in your `path`.
|
13
|
+
|
14
|
+
Compiling using ocra:
|
15
|
+
|
16
|
+
ocra --output notify-send windows/notify-send_growl_for_windows
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# vi: set ft=ruby :
|
4
|
+
|
5
|
+
# Example OS X terminal-notifier notify-send wrapper script.
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.on('-u', '--urgency LEVEL') { |v| options[:u] = v } # Option gets removed
|
13
|
+
opts.on('-t', '--expire-time TIME') { |v| options[:t] = v } # Option gets removed
|
14
|
+
opts.on('-a', '--app-name APP_NAME') { |v| options[:a] = v } # TO DO: Set to -title
|
15
|
+
opts.on('-i', '--icon ICON[,ICON...]') { |v| options[:i] = v } # Option gets removed
|
16
|
+
opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:c] = v } # Option gets removed
|
17
|
+
opts.on('-h', '--hint TYPE:NAME:VALUE') { |v| options[:h] = v } # Option gets removed
|
18
|
+
opts.on('-v', '--version') { |v| options[:v] = v } # Option gets removed
|
19
|
+
end.parse!
|
20
|
+
|
21
|
+
|
22
|
+
if ARGV.length == 0
|
23
|
+
puts "No summary specified"
|
24
|
+
exit 1
|
25
|
+
elsif ARGV.length == 1
|
26
|
+
message = "-message '\\#{ARGV[0]}'"
|
27
|
+
elsif ARGV.length == 2
|
28
|
+
message = "-title '\\#{ARGV[0]}' -message '\\#{ARGV[1]}'"
|
29
|
+
else
|
30
|
+
message = ARGV.map{|a| a =~ /-(title|message)/ ? a : "'\\#{a}'"}.join(' ')
|
31
|
+
end
|
32
|
+
|
33
|
+
system("terminal-notifier -sound default #{message}")
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# vi: set ft=ruby :
|
4
|
+
|
5
|
+
# Example MS-Windows notify-send wrapper script. Assumes growlnotify.exe is in your 'path'.
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: notify-send [options]"
|
12
|
+
|
13
|
+
opts.on('-u', '--urgency LEVEL') { |v| options[:u] = v } # TO DO: Set to /p:priority
|
14
|
+
opts.on('-t', '--expire-time TIME') { |v| options[:t] = v } # Option gets removed
|
15
|
+
opts.on('-a', '--app-name APP_NAME') { |v| options[:a] = v } # TO DO: Set to /a:application
|
16
|
+
opts.on('-i', '--icon ICON[,ICON...]') { |v| options[:i] = v } # TO DO: Set to /i:icon (url only)
|
17
|
+
opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:c] = v } # Option gets removed
|
18
|
+
opts.on('-h', '--hint TYPE:NAME:VALUE') { |v| options[:h] = v } # Option gets removed
|
19
|
+
opts.on('-v', '--version') { |v| options[:v] = v } # Option gets removed
|
20
|
+
end.parse!
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
if ARGV.length == 0
|
25
|
+
puts "No summary specified"
|
26
|
+
elsif ARGV.length == 1
|
27
|
+
message = "'#{ARGV[0]}'"
|
28
|
+
system("growlnotify.exe \"#{message}\"")
|
29
|
+
elsif ARGV.length == 2
|
30
|
+
title = "/t:'#{ARGV[0]}'"
|
31
|
+
message = "'#{ARGV[1]}'"
|
32
|
+
system("growlnotify.exe \"#{title}\" \"#{message}\"")
|
33
|
+
else
|
34
|
+
message = ARGV.map{|a| "'#{a}'"}.join(' ')
|
35
|
+
system("growlnotify.exe \"#{message}\"")
|
36
|
+
end
|
data/files/notify-send.erb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
# -*- mode: ruby -*-
|
3
3
|
# vi: set ft=ruby :
|
4
4
|
|
@@ -12,7 +12,7 @@ require 'fileutils'
|
|
12
12
|
|
13
13
|
options = {}
|
14
14
|
OptionParser.new do |opts|
|
15
|
-
opts.banner = "Usage:
|
15
|
+
opts.banner = "Usage: notify-send.rb [options]"
|
16
16
|
|
17
17
|
opts.on('-u', '--urgency LEVEL') { |v| options[:u] = v }
|
18
18
|
opts.on('-t', '--expire-time TIME') { |v| options[:t] = v }
|
@@ -36,11 +36,10 @@ end.join(' ')
|
|
36
36
|
|
37
37
|
# TODO: Need to escape values
|
38
38
|
unless ARGV.empty?
|
39
|
-
cmd <<
|
40
|
-
cmd << ARGV.map{|a| "'#{a}'"}.join(' ')
|
39
|
+
cmd << ARGV.map{|a| " '#{a}'"}.join(' ')
|
41
40
|
end
|
42
41
|
|
43
|
-
client_ip =
|
44
|
-
TCPSocket.open
|
42
|
+
client_ip = `ip route|grep default|awk '{print $3}'`
|
43
|
+
TCPSocket.open client_ip, <%= host_port %> do |s|
|
45
44
|
s.send cmd, 0
|
46
45
|
end
|
@@ -7,7 +7,7 @@ module Vagrant
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(env)
|
10
|
-
path = compile_command(env)
|
10
|
+
path = compile_command(env, 'notify-send.erb')
|
11
11
|
install_command_on_guest(env, path)
|
12
12
|
|
13
13
|
@app.call env
|
@@ -15,10 +15,10 @@ module Vagrant
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def compile_command(env)
|
18
|
+
def compile_command(env, template_file)
|
19
19
|
host_port = env[:notify_data][:port]
|
20
20
|
template_binding = OpenStruct.new(:host_port => host_port, :shared_folder => '/tmp/vagrant-notify')
|
21
|
-
command_template = ERB.new(Vagrant::Notify.files_path.join(
|
21
|
+
command_template = ERB.new(Vagrant::Notify.files_path.join(template_file).read)
|
22
22
|
command = command_template.result(template_binding.instance_eval { binding })
|
23
23
|
|
24
24
|
env[:tmp_path].join('vagrant-notify-send').open('w') { |f| f.write(command) }
|
@@ -29,6 +29,9 @@ module Vagrant
|
|
29
29
|
env[:machine].communicate.upload(source.to_s, '/tmp/notify-send')
|
30
30
|
env[:machine].communicate.sudo('mv /usr/bin/{notify-send,notify-send.bkp}; exit 0')
|
31
31
|
env[:machine].communicate.sudo('mv /tmp/notify-send /usr/bin/notify-send && chmod +x /usr/bin/notify-send')
|
32
|
+
if RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
33
|
+
env[:machine].communicate.sudo("sed 's/\r\$//' -i /usr/bin/notify-send") # dos2unix
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'windows/process_info'
|
2
|
+
|
1
3
|
module Vagrant
|
2
4
|
module Notify
|
3
5
|
module Action
|
@@ -18,9 +20,13 @@ module Vagrant
|
|
18
20
|
private
|
19
21
|
|
20
22
|
def valid_process?(pid)
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
if RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
24
|
+
Vagrant::Notify::Action::Windows::ProcessInfo.queryProcess(pid) if pid
|
25
|
+
else
|
26
|
+
Process.getpgid(pid.to_i) if pid
|
27
|
+
end
|
28
|
+
rescue Errno::ESRCH
|
29
|
+
false
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require "vagrant/util/is_port_open"
|
2
2
|
|
3
|
-
require_relative '../server'
|
4
3
|
|
5
4
|
module Vagrant
|
6
5
|
module Notify
|
@@ -16,8 +15,18 @@ module Vagrant
|
|
16
15
|
@env = env
|
17
16
|
|
18
17
|
port = next_available_port
|
19
|
-
env[:
|
20
|
-
|
18
|
+
id = env[:machine].id
|
19
|
+
dir = File.expand_path('../../', __FILE__)
|
20
|
+
|
21
|
+
if which('ruby')
|
22
|
+
env[:notify_data][:pid] = Process.spawn("ruby #{dir}/server.rb #{id} #{port}")
|
23
|
+
env[:notify_data][:port] = port
|
24
|
+
|
25
|
+
env[:machine].ui.success("Started vagrant-notify-server pid: #{env[:notify_data][:pid]}")
|
26
|
+
sleep 5
|
27
|
+
else
|
28
|
+
env[:machine].ui.error("Unable to spawn TCPServer daemon, ruby not found in $PATH")
|
29
|
+
end
|
21
30
|
|
22
31
|
@app.call env
|
23
32
|
end
|
@@ -56,6 +65,20 @@ module Vagrant
|
|
56
65
|
yield options
|
57
66
|
end
|
58
67
|
end
|
68
|
+
|
69
|
+
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
70
|
+
# Cross-platform way of finding an executable in the $PATH.
|
71
|
+
# which('ruby') #=> /usr/bin/ruby
|
72
|
+
def which(cmd)
|
73
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
74
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
75
|
+
exts.each { |ext|
|
76
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
77
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
return nil
|
81
|
+
end
|
59
82
|
end
|
60
83
|
end
|
61
84
|
end
|
@@ -16,7 +16,14 @@ module Vagrant
|
|
16
16
|
|
17
17
|
pid = env[:notify_data][:pid]
|
18
18
|
|
19
|
-
|
19
|
+
begin
|
20
|
+
Process.kill('KILL', pid.to_i)
|
21
|
+
env[:machine].ui.success("Stopped vagrant-notify-server pid: #{pid}")
|
22
|
+
rescue Errno::ESRCH
|
23
|
+
nil
|
24
|
+
rescue
|
25
|
+
env[:machine].ui.error("Failed to stop vagrant-notify-server pid: #{pid}")
|
26
|
+
end
|
20
27
|
|
21
28
|
env[:notify_data][:pid] = nil
|
22
29
|
env[:notify_data][:port] = nil
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module Vagrant
|
3
|
+
module Notify
|
4
|
+
module Action
|
5
|
+
module Windows
|
6
|
+
class ProcessInfo
|
7
|
+
def self.queryProcess(pid)
|
8
|
+
return false unless pid =~ /\A\d+\z/
|
9
|
+
result = `c\:/Windows/System32/wbem/WMIC.exe process where \"ProcessID = '#{pid}'\" get ProcessID,Commandline /format:list 2>nul`
|
10
|
+
querypid = false
|
11
|
+
result.split(/\r?\n/).each do |line|
|
12
|
+
next if line =~ /^\s*$/
|
13
|
+
if line =~ /ProcessId=(\d+)/i
|
14
|
+
querypid = $1.to_i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
return querypid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -52,6 +52,23 @@ module Vagrant
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
def action_status_server
|
57
|
+
Vagrant::Action::Builder.new.tap do |b|
|
58
|
+
b.use Call, CheckProvider do |env, b2|
|
59
|
+
next if !env[:result]
|
60
|
+
|
61
|
+
b2.use PrepareData
|
62
|
+
b2.use Call, ServerIsRunning do |env2, b3|
|
63
|
+
if env2[:result]
|
64
|
+
env[:machine].ui.success("vagrant-notify-server pid: #{env2[:notify_data][:pid]}")
|
65
|
+
else
|
66
|
+
env[:machine].ui.error("No vagrant-notify server detected.")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
55
72
|
end
|
56
73
|
end
|
57
74
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
require_relative 'action'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
module Notify
|
6
|
+
class Command < Vagrant.plugin('2', :command)
|
7
|
+
|
8
|
+
def self.synopsis
|
9
|
+
"plugin: vagrant-notify: forwards notify-send from guest to host machine and notifies provisioning status"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
options = {}
|
14
|
+
opts = OptionParser.new do |o|
|
15
|
+
o.banner = 'Usage: vagrant notify'
|
16
|
+
o.separator ''
|
17
|
+
o.version = Vagrant::Notify::VERSION
|
18
|
+
o.program_name = 'vagrant notify'
|
19
|
+
|
20
|
+
o.on('-h', '--help', 'Display this screen.' ) { options[:help] = true }
|
21
|
+
o.on('--status', 'Show vagrant-notify-server daemon status. (default)') { options[:status] = true }
|
22
|
+
o.on('--start', 'Manually start vagrant-notify-server daemon.') { options[:start] = true }
|
23
|
+
o.on('--stop', 'Manually stop vagrant-notify-server daemon.') { options[:stop] = true }
|
24
|
+
o.on('--restart', 'Manually restart vagrant-notify-server daemon.') { options[:restart] = true }
|
25
|
+
end
|
26
|
+
|
27
|
+
argv = parse_options(opts)
|
28
|
+
|
29
|
+
with_target_vms(argv, options) do |machine|
|
30
|
+
if options[:help]
|
31
|
+
@env.ui.info(opts)
|
32
|
+
return 0
|
33
|
+
end
|
34
|
+
if options[:status] || options.length == 0
|
35
|
+
@env.action_runner.run(Vagrant::Notify::Action.action_status_server, {
|
36
|
+
:machine => machine,
|
37
|
+
})
|
38
|
+
return 0
|
39
|
+
end
|
40
|
+
if options[:stop]
|
41
|
+
@env.action_runner.run(Vagrant::Notify::Action.action_stop_server, {
|
42
|
+
:machine => machine,
|
43
|
+
})
|
44
|
+
return 0
|
45
|
+
end
|
46
|
+
if options[:start]
|
47
|
+
@env.action_runner.run(Vagrant::Notify::Action.action_start_server, {
|
48
|
+
:machine => machine,
|
49
|
+
})
|
50
|
+
return 0
|
51
|
+
end
|
52
|
+
if options[:restart]
|
53
|
+
@env.action_runner.run(Vagrant::Notify::Action.action_stop_server, {
|
54
|
+
:machine => machine,
|
55
|
+
})
|
56
|
+
@env.action_runner.run(Vagrant::Notify::Action.action_start_server, {
|
57
|
+
:machine => machine,
|
58
|
+
})
|
59
|
+
return 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -13,7 +13,7 @@ module Vagrant
|
|
13
13
|
# possible provider action class that Vagrant might have
|
14
14
|
start_server_hook = lambda do |hook|
|
15
15
|
require_relative './action'
|
16
|
-
hook.after VagrantPlugins::ProviderVirtualBox::Action::
|
16
|
+
hook.after VagrantPlugins::ProviderVirtualBox::Action::WaitForCommunicator, Vagrant::Notify::Action.action_start_server
|
17
17
|
|
18
18
|
if defined?(Vagrant::LXC)
|
19
19
|
require 'vagrant-lxc/action'
|
@@ -23,6 +23,7 @@ module Vagrant
|
|
23
23
|
|
24
24
|
action_hook 'start-server-after-boot-on-machine-up', :machine_action_up, &start_server_hook
|
25
25
|
action_hook 'start-server-after-boot-on-machine-reload', :machine_action_reload, &start_server_hook
|
26
|
+
action_hook 'start-server-after-resume-on-machine', :machine_action_resume, &start_server_hook
|
26
27
|
|
27
28
|
share_folder_hook = lambda do |hook|
|
28
29
|
require_relative './action'
|
@@ -36,6 +37,7 @@ module Vagrant
|
|
36
37
|
hook.before Vagrant::Action::Builtin::GracefulHalt, Vagrant::Notify::Action.action_stop_server
|
37
38
|
end
|
38
39
|
|
40
|
+
|
39
41
|
# TODO: This should be generic, we don't want to hard code every single
|
40
42
|
# possible provider action class that Vagrant might have
|
41
43
|
action_hook 'stop-server-before-destroy', :machine_action_destroy do |hook|
|
@@ -47,6 +49,16 @@ module Vagrant
|
|
47
49
|
hook.before Vagrant::LXC::Action::Destroy, Vagrant::Notify::Action.action_stop_server
|
48
50
|
end
|
49
51
|
end
|
52
|
+
|
53
|
+
action_hook 'stop-server-after-suspend', :machine_action_suspend do |hook|
|
54
|
+
require_relative './action'
|
55
|
+
hook.before VagrantPlugins::ProviderVirtualBox::Action::Suspend, Vagrant::Notify::Action.action_stop_server
|
56
|
+
end
|
57
|
+
|
58
|
+
command(:notify) do
|
59
|
+
require_relative 'command'
|
60
|
+
Vagrant::Notify::Command
|
61
|
+
end
|
50
62
|
end
|
51
63
|
end
|
52
64
|
end
|
@@ -1,21 +1,31 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
1
3
|
module Vagrant
|
2
4
|
module Notify
|
3
5
|
class Server
|
4
6
|
HTTP_RESPONSE = "Hi! You just reached the vagrant notification server"
|
5
7
|
|
6
|
-
def self.run(
|
7
|
-
id = env[:machine].id
|
8
|
-
machine_name = env[:machine].name
|
9
|
-
provider = env[:machine].provider_name
|
10
|
-
|
11
|
-
|
12
|
-
tcp_server = TCPServer.open(port)
|
8
|
+
def self.run(id, port, machine_name='default', provider='virtualbox')
|
9
|
+
#id = env[:machine].id
|
10
|
+
#machine_name = env[:machine].name
|
11
|
+
#provider = env[:machine].provider_name
|
12
|
+
|
13
|
+
if __FILE__ == $0
|
14
|
+
tcp_server = TCPServer.open("127.0.0.1", port)
|
13
15
|
server = self.new(id, machine_name, provider)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
# Have to wrap this in a begin/rescue block so we can be certain the server is running at all times.
|
18
|
+
begin
|
19
|
+
loop {
|
20
|
+
Thread.start(tcp_server.accept) { |client|
|
21
|
+
Thread.handle_interrupt(Interrupt => :never) {
|
22
|
+
server.receive_data(client)
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
rescue Interrupt
|
27
|
+
retry
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
@@ -68,3 +78,10 @@ module Vagrant
|
|
68
78
|
end
|
69
79
|
end
|
70
80
|
end
|
81
|
+
|
82
|
+
|
83
|
+
# Ghetto
|
84
|
+
id = ARGV[0]
|
85
|
+
port = ARGV[1]
|
86
|
+
|
87
|
+
Vagrant::Notify::Server.run(id,port)
|
data/lib/vagrant-notify.rb
CHANGED
@@ -2,11 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'vagrant-notify/action/start_server'
|
4
4
|
|
5
|
+
require 'vagrant-notify/server'
|
6
|
+
|
5
7
|
describe Vagrant::Notify::Action::StartServer do
|
6
|
-
let(:app)
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
8
|
+
let(:app) { lambda { |env| } }
|
9
|
+
let(:ui) { mock(success: true)}
|
10
|
+
let(:id) { '425e799c-1293-4939-bo39-263lcc7457e8' }
|
11
|
+
let(:machine) { mock(state: stub(id: :stopped), ui: ui, id: id) }
|
12
|
+
let(:env) { {notify_data: {}, machine: machine} }
|
13
|
+
let(:pid) { '42' }
|
14
|
+
let(:port) { '1234' }
|
10
15
|
|
11
16
|
subject { described_class.new(app, env) }
|
12
17
|
|
@@ -16,17 +21,18 @@ describe Vagrant::Notify::Action::StartServer do
|
|
16
21
|
subject.call(env)
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'persists pid number' do
|
24
|
-
env[:notify_data][:pid].should == pid
|
24
|
+
after do
|
25
|
+
Process.kill('KILL', env[:notify_data][:pid].to_i)
|
25
26
|
end
|
26
27
|
|
27
|
-
it 'persists used port' do
|
28
|
+
it 'starts the server and persists used port' do
|
28
29
|
env[:notify_data][:port].should == port
|
29
30
|
end
|
30
31
|
|
32
|
+
# need proper test of this
|
33
|
+
# it "removes server PID from notify data" do
|
34
|
+
# env[:notify_data][:pid].should be_nil
|
35
|
+
# end
|
36
|
+
|
31
37
|
pending 'identifies the next available port'
|
32
|
-
end
|
38
|
+
end
|
@@ -5,7 +5,8 @@ require 'vagrant-notify/action/stop_server'
|
|
5
5
|
describe Vagrant::Notify::Action::StopServer do
|
6
6
|
let(:app) { lambda { |env| } }
|
7
7
|
let(:communicator) { mock(sudo: true) }
|
8
|
-
let(:
|
8
|
+
let(:ui) { mock(success: true)}
|
9
|
+
let(:machine) { mock(communicate: communicator, state: stub(id: :running), ui: ui) }
|
9
10
|
let(:env) { {notify_data: {pid: pid, port: 1234}, machine: machine} }
|
10
11
|
let(:pid) { '42' }
|
11
12
|
let(:port) { described_class::PORT }
|
data/vagrant-notify.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'vagrant-notify/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "vagrant-notify"
|
8
8
|
gem.version = Vagrant::Notify::VERSION
|
9
|
-
gem.authors = ["Fabio Rehm"]
|
10
|
-
gem.email = ["fgrehm@gmail.com"]
|
9
|
+
gem.authors = ["Fabio Rehm", "Tony Baltazar"]
|
10
|
+
gem.email = ["fgrehm@gmail.com", "root@rubyninja.org"]
|
11
11
|
gem.description = 'A Vagrant plugin that forwards `notify-send` from guest to host machine and notifies provisioning status'
|
12
12
|
gem.summary = gem.description
|
13
13
|
gem.homepage = "https://github.com/fgrehm/vagrant-notify"
|
metadata
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Rehm
|
8
|
+
- Tony Baltazar
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
14
|
description: A Vagrant plugin that forwards `notify-send` from guest to host machine
|
14
15
|
and notifies provisioning status
|
15
16
|
email:
|
16
17
|
- fgrehm@gmail.com
|
18
|
+
- root@rubyninja.org
|
17
19
|
executables: []
|
18
20
|
extensions: []
|
19
21
|
extra_rdoc_files: []
|
@@ -29,6 +31,9 @@ files:
|
|
29
31
|
- README.md
|
30
32
|
- Rakefile
|
31
33
|
- development/Vagrantfile
|
34
|
+
- examples/README.md
|
35
|
+
- examples/osx/notify-send_terminal-notifier
|
36
|
+
- examples/windows/notify-send_growl_for_windows
|
32
37
|
- files/notify-send.erb
|
33
38
|
- lib/vagrant-notify.rb
|
34
39
|
- lib/vagrant-notify/action.rb
|
@@ -40,6 +45,8 @@ files:
|
|
40
45
|
- lib/vagrant-notify/action/set_shared_folder.rb
|
41
46
|
- lib/vagrant-notify/action/start_server.rb
|
42
47
|
- lib/vagrant-notify/action/stop_server.rb
|
48
|
+
- lib/vagrant-notify/action/windows/process_info.rb
|
49
|
+
- lib/vagrant-notify/command.rb
|
43
50
|
- lib/vagrant-notify/data.rb
|
44
51
|
- lib/vagrant-notify/plugin.rb
|
45
52
|
- lib/vagrant-notify/server.rb
|
@@ -72,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
79
|
version: '0'
|
73
80
|
requirements: []
|
74
81
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.5.1
|
76
83
|
signing_key:
|
77
84
|
specification_version: 4
|
78
85
|
summary: A Vagrant plugin that forwards `notify-send` from guest to host machine and
|