easy-serve 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03c328ab82c8bb6aebbc3b9e6e5c9a50a3895a5c
4
- data.tar.gz: be6c2705dc58ee78cf2ce725f0bdb885dac96378
3
+ metadata.gz: 2d1ef7c230f25e932ca33c4acbf8836789aeba20
4
+ data.tar.gz: 6003abf5645a32b1aadee49e711fbed4cfe8a8f4
5
5
  SHA512:
6
- metadata.gz: d91ad208ac5237e50d2e03ca0d1524a2a8005753f78fa1ccf192b7486baa8ce70abca4c2b8ca7ecfaa25c2d364f1d0f5a6dcf6759fb2916557a3b9e9ca31b64f
7
- data.tar.gz: 22d93a3d940daf5e2ecf4810896f9f13fbef3d49e8cad7f7f2b9a1a07991f1d4bb106163e55dfaf9d70f7a8dec8ed0bbc0a6b5a76b3856c74fbafa50e7e76491
6
+ metadata.gz: 0618e996740b75fefef23d2fda92fc2f39a1e13d8e6d66d6d18c61f613c44aefd7419e49587b909bbc2c1aa86e9e605588c4f4f59d6b1311dfe18a87da77c448
7
+ data.tar.gz: 579718d353ad19562bb10a0dfdd0e9574476eeba4116844328a04e53ee0b13bf454cafa94a8194419a29eab912342e42297b2c778edf3c542cc623f0fbfcf2df
data/lib/easy-serve.rb CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  require 'easy-serve/service'
7
7
 
8
8
  class EasyServe
9
- VERSION = "0.8"
9
+ VERSION = "0.9"
10
10
 
11
11
  class EasyFormatter < Logger::Formatter
12
12
  Format = "%s: %s: %s\n"
@@ -16,17 +16,34 @@ class EasyServe
16
16
  end
17
17
 
18
18
  fwd = "0:#{service_host}:#{service.port}"
19
- out = `ssh -O forward -R #{fwd} #{host}`
19
+ remote_port = nil
20
+ tries = 10
21
+ 1.times do
22
+ out = `ssh -O forward -R #{fwd} #{host}`
23
+ begin
24
+ remote_port = Integer(out)
25
+ rescue
26
+ log.error "Unable to set up dynamic ssh port forwarding. " +
27
+ "Please check if ssh -v is at least 6.0."
28
+ raise
29
+ end
20
30
 
21
- begin
22
- remote_port = Integer(out)
23
- rescue
24
- log.error "Unable to set up dynamic ssh port forwarding. " +
25
- "Please check if ssh -v is at least 6.0."
26
- raise
31
+ if remote_port == 0
32
+ log.warn "race condition in ssh selection of remote_port"
33
+ tries -= 1
34
+ if tries > 0
35
+ sleep 0.1
36
+ log.info "retrying ssh selection of remote_port"
37
+ redo
38
+ end
39
+ raise "ssh did not assign remote_port"
40
+ end
27
41
  end
28
42
 
29
- at_exit {system "ssh -O cancel -R #{fwd} #{host}"}
43
+ # This breaks with multiple forward requests, and it would be too hard
44
+ # to coordinate among all requesting processes, so let's leave the
45
+ # forwarding open:
46
+ #at_exit {system "ssh -O cancel -R #{fwd} #{host}"}
30
47
 
31
48
  TCPService.new service.name, connect_host: "localhost", port: remote_port
32
49
  end
@@ -2,7 +2,26 @@ class EasyServe
2
2
  # Refers to a named service. Use the #serve method to start the service.
3
3
  # Encapsulates current location and identity, including pid and address. A
4
4
  # Service object can be serialized to a remote process so it can #connect to
5
- # the service.
5
+ # the service.
6
+ #
7
+ # The scheme for referencing hosts is as follows:
8
+ #
9
+ # bind host | connect host
10
+ # +------------------------------------------------------
11
+ # | local remote TCP SSH tunnel
12
+ # -----------+------------------------------------------------------
13
+ #
14
+ # localhost 'localhost' X 'localhost'
15
+ #
16
+ # 0.0.0.0 'localhost' hostname(*) 'localhost'
17
+ #
18
+ # hostname hostname hostname 'localhost'(**)
19
+ #
20
+ # * use hostname as best guess, can override; append ".local" if
21
+ # hostname not qualified
22
+ #
23
+ # ** forwarding set up to hostname[.local] instead of localhost
24
+ #
6
25
  class Service
7
26
  attr_reader :name
8
27
  attr_reader :pid
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-serve
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel VanderWerf