Module: Bosh::Deployer::InstanceManagerHelpers
- Defined in:
- lib/deployer/instance_manager_helpers.rb
Instance Method Summary collapse
Instance Method Details
#process_exists?(pid) ⇒ Boolean
9 10 11 12 13 14 15 |
# File 'lib/deployer/instance_manager_helpers.rb', line 9 def process_exists?(pid) begin Process.kill(0, pid) rescue Errno::ESRCH false end end |
#socket_readable?(ip, port) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/deployer/instance_manager_helpers.rb', line 17 def socket_readable?(ip, port) socket = TCPSocket.new(ip, port) if IO.select([socket], nil, nil, 5) logger.debug("tcp socket #{ip}:#{port} is readable") yield true else false end rescue SocketError => e logger.debug("tcp socket #{ip}:#{port} SocketError: #{e.inspect}") sleep 1 false rescue SystemCallError => e logger.debug("tcp socket #{ip}:#{port} SystemCallError: #{e.inspect}") sleep 1 false ensure socket.close if socket end |
#tunnel(port) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/deployer/instance_manager_helpers.rb', line 38 def tunnel(port) return if @session ip = discover_bosh_ip loop until socket_readable?(ip, @ssh_port) do #sshd is up, sleep while host keys are generated sleep @ssh_wait end lo = "127.0.0.1" cmd = "ssh -R #{port}:#{lo}:#{port} #{@ssh_user}@#{ip}" logger.info("Preparing for ssh tunnel: #{cmd}") loop do begin @session = Net::SSH.start(ip, @ssh_user, :keys => [@ssh_key], :paranoid => false) logger.debug("ssh #{@ssh_user}@#{ip}: ESTABLISHED") break rescue => e logger.debug("ssh start #{@ssh_user}@#{ip} failed: #{e.inspect}") sleep 1 end end @session.forward.remote(port, lo, port) logger.info("`#{cmd}` started: OK") Thread.new do begin @session.loop { true } rescue IOError => e logger.debug("`#{cmd}` terminated: #{e.inspect}") @session = nil end end end |