Cleans up ssh-forwarded ports on VM halt/destroy.
# File lib/vagrant-libvirt/action/forward_ports.rb, line 122 def initialize(app, env) @app = app @logger = Log4r::Logger.new( 'vagrant_libvirt::action::clear_forward_ports' ) end
# File lib/vagrant-libvirt/action/forward_ports.rb, line 129 def call(env) @env = env if ssh_pids.any? env[:ui].info I18n.t( 'vagrant.actions.vm.clear_forward_ports.deleting' ) ssh_pids.each do |pid| next unless ssh_pid?(pid) @logger.debug "Killing pid #{pid}" system "kill #{pid}" end @logger.info 'Removing ssh pid files' remove_ssh_pids else @logger.info 'No ssh pids found' end @app.call env end
# File lib/vagrant-libvirt/action/forward_ports.rb, line 166 def remove_ssh_pids glob = @env[:machine].data_dir.join('pids').to_s + '/ssh_*.pid' Dir[glob].each do |file| File.delete file end end
# File lib/vagrant-libvirt/action/forward_ports.rb, line 160 def ssh_pid?(pid) @logger.debug 'Checking if #{pid} is an ssh process ' 'with `ps -o cmd= #{pid}`' %xps -o cmd= #{pid}`.strip.chomp =~ /ssh/ end
# File lib/vagrant-libvirt/action/forward_ports.rb, line 153 def ssh_pids glob = @env[:machine].data_dir.join('pids').to_s + '/ssh_*.pid' @ssh_pids = Dir[glob].map do |file| File.read(file).strip.chomp end end