Class: VagrantPlugins::VagrantNotifyForwarder::Action::StopHostForwarder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-notify-forwarder/action/stop_host_forwarder.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ StopHostForwarder

Returns a new instance of StopHostForwarder.



7
8
9
# File 'lib/vagrant-notify-forwarder/action/stop_host_forwarder.rb', line 7

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-notify-forwarder/action/stop_host_forwarder.rb', line 11

def call(env)
  @app.call env

  return unless env[:machine].config.notify_forwarder.enable

  pidfile = Utils.host_pidfile env

  if File.exist? pidfile
    pidfile.open('r') do |f|
      f.readlines.each do |process|
        pid = process.to_i
        begin
          Process.kill 'TERM', pid
        rescue Errno::ESRCH
        end
      end
      pidfile.delete
    end
  end
end