Class: VagrantPlugins::VagrantNotifyForwarder::Action::StartHostForwarder
- Inherits:
-
Object
- Object
- VagrantPlugins::VagrantNotifyForwarder::Action::StartHostForwarder
- Defined in:
- lib/vagrant-notify-forwarder/action/start_host_forwarder.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #ensure_binary_downloaded(env) ⇒ Object
-
#initialize(app, env) ⇒ StartHostForwarder
constructor
A new instance of StartHostForwarder.
- #start_watcher(env, command) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ StartHostForwarder
Returns a new instance of StartHostForwarder.
7 8 9 |
# File 'lib/vagrant-notify-forwarder/action/start_host_forwarder.rb', line 7 def initialize(app, env) @app = app end |
Instance Method Details
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-notify-forwarder/action/start_host_forwarder.rb', line 33 def call(env) if env[:machine].config.notify_forwarder.enable port = env[:machine].config.notify_forwarder.port env[:machine].config.vm.network :forwarded_port, host: port, guest: port, protocol: 'udp', auto_correct: true end @app.call env if env[:machine].config.notify_forwarder.enable path = ensure_binary_downloaded env return unless path env[:machine].config.vm.synced_folders.each do |id, | unless [:disabled] hostpath = File.([:hostpath], env[:root_path]) guestpath = [:guestpath] args = "watch -c 127.0.0.1:#{port} #{hostpath} #{guestpath}" start_watcher env, "#{path} #{args}" env[:ui].detail("Notify-forwarder: host sending file change notifications to 127.0.0.1:#{port}") env[:ui].detail("Notify-forwarder: host forwarding notifications on #{hostpath} to #{guestpath}") end end end end |
#ensure_binary_downloaded(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vagrant-notify-forwarder/action/start_host_forwarder.rb', line 11 def ensure_binary_downloaded(env) os = Utils.parse_os_name `uname -s` hardware = Utils.parse_hardware_name `uname -m` env[:ui].error "Notify-forwarder: Unsupported host operating system (detected: #{os})" if os == :unsupported env[:ui].error "Notify-forwarder: Unsupported host hardware (detected: #{hardware})" if hardware == :unsupported if os != :unsupported and hardware != :unsupported Utils.ensure_binary_downloaded env, os, hardware end end |
#start_watcher(env, command) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-notify-forwarder/action/start_host_forwarder.rb', line 23 def start_watcher(env, command) pid = Process.spawn command Process.detach(pid) pidfile = Utils.host_pidfile env pidfile.open('a+') do |f| f.write("#{pid}\n") end end |