class Dizby::BasicSpawnTunnel
Public Class Methods
new(*abstract_args, spawn_args)
click to toggle source
Calls superclass method
Dizby::AbstractTunnel::new
# File lib/dizby/tunnel/basic_spawn.rb, line 12 def initialize(*abstract_args, spawn_args) @command = spawn_args.command super(*abstract_args, **spawn_args.options) end
Public Instance Methods
get_and_write_ports(ssh, output)
click to toggle source
Calls superclass method
Dizby::AbstractTunnel#get_and_write_ports
# File lib/dizby/tunnel/basic_spawn.rb, line 18 def get_and_write_ports(ssh, output) @command.set_dynamic_mode if @strategy.server_port.zero? @channel = ssh.open_channel do |ch| ch.exec @command.to_cmd do |_, success| raise SpawnError, 'could not spawn host' unless success # it is already triggered if the port is set get_remote_server_port(ch) if @command.dynamic? end end ssh.loop { !@channel[:triggered] } if @command.dynamic? @channel.eof! super end
get_remote_server_port(ch)
click to toggle source
# File lib/dizby/tunnel/basic_spawn.rb, line 37 def get_remote_server_port(ch) ch[:data] = '' ch[:triggered] = false ch.on_data { |_, data| ch[:data] << data } ch.on_extended_data { |_, _, data| @server.log.error(data.inspect) } ch.on_process do |_| if !ch[:triggered] && ch[:data] =~ /Running on port (\d+)\./ @strategy.instance_variable_set(:@server_port, $~[1]) ch[:triggered] = true end end end
wait(ssh)
click to toggle source
# File lib/dizby/tunnel/basic_spawn.rb, line 52 def wait(ssh) ssh.loop { @channel.active? } end