Class: SSHTunnel
- Inherits:
-
Object
- Object
- SSHTunnel
- Defined in:
- lib/shared/ssh_tunnel.rb
Constant Summary collapse
- TIMEOUT_SECONDS =
10 seconds was too short for users with poorer connections.
15
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(host, user, local_port = 2288) ⇒ SSHTunnel
constructor
A new instance of SSHTunnel.
- #open ⇒ Object
Constructor Details
#initialize(host, user, local_port = 2288) ⇒ SSHTunnel
Returns a new instance of SSHTunnel.
8 9 10 |
# File 'lib/shared/ssh_tunnel.rb', line 8 def initialize(host, user, local_port = 2288) @host, @user, @local_port = host, user, local_port end |
Instance Method Details
#connect ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/shared/ssh_tunnel.rb', line 28 def connect @thread.kill if @thread @thread = Thread.new do Net::SSH.start(@host, @user, { :timeout => TIMEOUT_SECONDS }) do |ssh| ssh.forward.local(@local_port, 'localhost', Testbot::SERVER_PORT) ssh.loop { @up = true } end end end |
#open ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/shared/ssh_tunnel.rb', line 12 def open connect start_time = Time.now while true break if @up sleep 0.5 if Time.now - start_time > TIMEOUT_SECONDS puts "SSH connection failed, trying again... (#{@user}@#{@host})" start_time = Time.now connect end end end |