Module: Dory::PortUtils

Defined in:
lib/dory/port_utils.rb

Class Method Summary collapse

Class Method Details

.check_port(port_num = self.port) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dory/port_utils.rb', line 5

def self.check_port(port_num = self.port)
  puts "Requesting sudo to check if something is bound to port #{port_num}".green
  ret = Dory::Sh.run_command("sudo lsof -i :#{port_num}")
  return [] unless ret.success?

  list = ret.stdout.split("\n")
  list.shift  # get rid of the column headers
  list.map! do |process|
    command, pid, user, fd, type, device, size, node, name = process.split(/\s+/)
    OpenStruct.new({
      command: command,
      pid: pid,
      user: user,
      fd: fd,
      type: type,
      device: device,
      size: size,
      node: node,
      name: name
    })
  end
end