Class: Vagrant::Notify::Server
- Inherits:
-
Object
- Object
- Vagrant::Notify::Server
- Defined in:
- lib/vagrant-notify/server.rb
Constant Summary collapse
- HTTP_RESPONSE =
"Hi! You just reached the vagrant notification server"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, machine_name = :default, provider = :virtualbox) ⇒ Server
constructor
A new instance of Server.
- #receive_data(client) ⇒ Object
Constructor Details
#initialize(id, machine_name = :default, provider = :virtualbox) ⇒ Server
Returns a new instance of Server.
36 37 38 39 40 |
# File 'lib/vagrant-notify/server.rb', line 36 def initialize(id, machine_name = :default, provider = :virtualbox) @id = id @machine_name = machine_name @provider = provider end |
Class Method Details
.run(id, port, bind_ip, machine_name = 'default', provider = 'virtualbox') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-notify/server.rb', line 8 def self.run(id, port, bind_ip, machine_name='default', provider='virtualbox') #id = env[:machine].id #machine_name = env[:machine].name #provider = env[:machine].provider_name if __FILE__ == $0 begin tcp_server = TCPServer.open(bind_ip, port) rescue exit 1 end server = self.new(id, machine_name, provider) # Have to wrap this in a begin/rescue block so we can be certain the server is running at all times. begin loop { Thread.start(tcp_server.accept) { |client| Thread.handle_interrupt(Interrupt => :never) { server.receive_data(client) } } } rescue Interrupt retry end end end |
Instance Method Details
#receive_data(client) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-notify/server.rb', line 42 def receive_data(client) args = read_args(client) if http_request?(args) client.puts HTTP_RESPONSE else fix_icon_path!(args) system("notify-send #{args}") end client.close rescue => ex log ex. end |