envoy-proxy 0.0.16 → 0.0.17

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: cc8414d24201c9196eabae2e64e25b62c971a104
4
- data.tar.gz: bca21d64b3aa9b7ada87de0e0b662ea5a3d5b3ea
3
+ metadata.gz: 5c6a64248f11bee0dcc828dfd58f77809175820a
4
+ data.tar.gz: 67ec9e035d118f7d0b80ef6ddecc9da019b72597
5
5
  SHA512:
6
- metadata.gz: 2f26ce559fd86e362372202f5c9e3361333ca593f51e584ce09f6267cb980f968800a47cff8209e32d098b8fa3b6e52275a7e6b82a5f49fcecb6082d9365ae5e
7
- data.tar.gz: 09f52e2d4b4dccb0c4b40fd4816877f75eaabda436d8797c69b315cbb6ef0804ddd72b0aca825a8bff743a8eb237af8d2a6bde00530ab7493c98f613ef8587d8
6
+ metadata.gz: 395ebb8755c9fafc317e17778b3d45b467f654af150dc98f1fb317a55f7acb4ca426efa63e6118abcdec33486137983ae5623fbf33eec867aa3f237274f1c5dc
7
+ data.tar.gz: 8cd6ed01cc0b23a387aa765914721db7116b5f72f773e907041745d21aeabcf6174ac8ffcda6c22d2be3c92b1246398ab2db0441d5386f2b272ea8c260812f0d
data/README.md CHANGED
@@ -29,3 +29,37 @@ specified host and port, which default to 0.0.0.0 and 8080.
29
29
  If KEY is specified, clients _must_ specify that key.
30
30
 
31
31
  The ZONE specifies the domain name suffix.
32
+
33
+ ## Advanced Client Configuration
34
+
35
+ The client will search up from the current directory for a .envoy file. If it
36
+ exists, it must be a YAML file containing either one hash of command line
37
+ options, or an array of multiple options. This file can also contain settings
38
+ which will execute a command if a local connection is refused.
39
+
40
+ | Option | Description | Default |
41
+ | ------------- | ----------------------- | - |
42
+ | `host` | The domain name prefix | None |
43
+ | `local_port` | The local port to use | None |
44
+ | `local_host` | The local host to use | 127.0.0.1 |
45
+ | `server_host` | The server host to use | p45.eu |
46
+ | `server_port` | The server port to use | 8282 |
47
+ | `tls` | Use TLS in the server connections | false |
48
+ | `verbose` | Be noisy | false |
49
+ | `command` | A command to run if a local connection is refused | None |
50
+ | `command_delay` | Number of seconds to wait before reconnecting, after starting a command | 1 |
51
+ | `dir` | A directory to change to | . |
52
+
53
+ If no host is specified, a random one is selected by the server.
54
+ If no local port is specified, a random one is selected by the client.
55
+ The command is processed for % substitions against the configuration hash,
56
+ including any randomly selected local port.
57
+
58
+ e.g. To start a rails app, you might use this configuration:
59
+
60
+ host: my_app
61
+ dir: ~/apps/my_app
62
+ command: rails s -p %{local_port}
63
+
64
+ You can still specify a constant local port, if you prefer that.
65
+
@@ -1,20 +1,65 @@
1
1
 
2
2
  module Envoy
3
+
3
4
  module Client
4
5
 
5
6
  module Channel
6
7
 
7
8
  def initialize id, client
8
9
  @id, @client = id, client
10
+ @buffer = ""
9
11
  super()
10
12
  end
11
13
 
14
+ def connection_completed
15
+ send_data @buffer, true
16
+ @buffer = nil
17
+ end
18
+
19
+ def send_data data, force = false
20
+ if !@buffer or force
21
+ super data
22
+ else
23
+ @buffer << data
24
+ end
25
+ end
26
+
12
27
  def receive_data data
13
28
  @client.send_object :stream, @id, data
14
29
  end
15
30
 
16
- def unbind
17
- @client.send_object :close, @id
31
+ def reconnect
32
+ super @client.options[:local_host], @client.options[:local_port]
33
+ end
34
+
35
+ def unbind e
36
+ if e == Errno::ECONNREFUSED
37
+ if @tried_starting
38
+ @client.log "Service isn't running, but starting it didn't really work out."
39
+ @client.send_object :close, @id, 502
40
+ elsif cmd = @client.options[:command]
41
+ cmd = cmd % @client.options
42
+ @client.log "Service doesn't seem to be running. Trying to start it now..."
43
+ @tried_starting = true
44
+ Dir.chdir File.expand_path(@client.options[:dir]) do
45
+ fork do
46
+ #Process.daemon(true, false)
47
+ ENV.delete("GEM_HOME")
48
+ ENV.delete("GEM_PATH")
49
+ ENV.delete("BUNDLE_BIN_PATH")
50
+ ENV.delete("BUNDLE_GEMFILE")
51
+ system cmd
52
+ end
53
+ end
54
+ EM.add_timer @client.options[:delay] do
55
+ reconnect
56
+ end
57
+ end
58
+ elsif e
59
+ @client.log e.inspect
60
+ else
61
+ @client.send_object :close, @id
62
+ end
18
63
  end
19
64
 
20
65
  end
@@ -31,4 +76,6 @@ module Envoy
31
76
  end
32
77
 
33
78
  end
79
+
34
80
  end
81
+
@@ -1,61 +1,38 @@
1
1
  require 'envoy/client/trunk'
2
+ require 'envoy/client/option_parser'
2
3
  require 'envoy/version'
4
+ require 'yaml'
3
5
 
4
- require 'optparse'
5
- require 'ostruct'
6
-
7
- options = {
8
- server_host: 'p45.eu',
9
- server_port: "8282",
10
- local_host: '127.0.0.1',
11
- local_port: "80",
12
- tls: false,
13
- verbose: false,
14
- version: Envoy::VERSION
15
- }
6
+ def find_config
7
+ dirs = Dir.pwd.split("/")
8
+ r = dirs.reduce([]) do |m, x|
9
+ [[*m[0], x], *m]
10
+ end.map do |p|
11
+ p.join("/") + "/.envoy"
12
+ end.each do |p|
13
+ return p if File.exist?(p)
14
+ end
15
+ false
16
+ end
16
17
 
17
- OptionParser.new do |op|
18
- op.banner = "Usage: #{$0} [options] [[HOST:]PORT]"
19
- op.on "--host HOST", "Allocate this domain label on the proxy" do |v|
20
- options[:hosts] ||= []
21
- options[:hosts] << v
22
- end
23
- op.on "-k", "--key KEY" do |v|
24
- options[:key] = v
25
- end
26
- op.on "-t", "--[no-]tls", "Encrypt communications with the envoy server" do |v|
27
- options[:tls] = v
28
- end
29
- op.on "-s", "--server SERVER", "Specify envoy/proxylocal server" do |v|
30
- host, port = v.split(":")
31
- options[:server_host] = host
32
- options[:server_port] ||= port
33
- end
34
- op.on "-v", "--[no-]verbose", "Be noisy about what's happening" do |v|
35
- options[:verbose] = v
36
- end
37
- op.on "-h", "--help", "Show this message" do
38
- puts op
39
- exit
40
- end
41
- op.on "--version" do
42
- puts Envoy::VERSION
43
- exit
44
- end
45
- op.parse!
46
- case ARGV[0]
47
- when /^(\d+)$/
48
- options[:local_port] = $1
49
- when /^(\[[^\]+]\]|[^:]+):(\d+)$/x
50
- options[:local_host] = $1
51
- options[:local_port] = $2
52
- when /^(.*)$/
53
- options[:local_host] = $1
54
- end
18
+ def load_config
19
+ conf = YAML.load(File.read(find_config))
20
+ conf.is_a?(Array) ? conf : [conf]
55
21
  end
56
22
 
23
+ options = parse_options
24
+
57
25
  unless EM.reactor_running?
58
26
  EM.run do
59
- Envoy::Client::Trunk.start options
27
+ load_config.each do |config|
28
+ config["local_port"] ||= rand(16383) + 49152
29
+ config = options.merge(config)
30
+ config["hosts"] ||= [config.delete("host")]
31
+ config = config.each_with_object({}) do |(k, v), h|
32
+ h[k.to_sym] = v
33
+ end
34
+ Envoy::Client::Trunk.start p config
35
+ end
60
36
  end
61
- end
37
+ end
38
+
@@ -0,0 +1,59 @@
1
+ require 'optparse'
2
+
3
+ def default_options
4
+ {
5
+ "server_host" => 'p45.eu',
6
+ "server_port" => "8282",
7
+ "local_host" => '127.0.0.1',
8
+ "tls" => false,
9
+ "verbose" => false,
10
+ "version" => Envoy::VERSION,
11
+ "command_delay" => 1,
12
+ "dir" => "."
13
+ }
14
+ end
15
+
16
+ def parse_options
17
+ options = default_options
18
+ OptionParser.new do |op|
19
+ op.banner = "Usage: #{$0} [options] [[HOST:]PORT]"
20
+ op.on "--host HOST", "Allocate this domain label on the proxy" do |v|
21
+ options["hosts"] ||= []
22
+ options["hosts"] << v
23
+ end
24
+ op.on "-k", "--key KEY" do |v|
25
+ options["key"] = v
26
+ end
27
+ op.on "-t", "--[no-]tls", "Encrypt communications with the envoy server" do |v|
28
+ options["tls"] = v
29
+ end
30
+ op.on "-s", "--server SERVER", "Specify envoy/proxylocal server" do |v|
31
+ host, port = v.split(":")
32
+ options["server_host"] = host
33
+ options["server_port"] ||= port
34
+ end
35
+ op.on "-v", "--[no-]verbose", "Be noisy about what's happening" do |v|
36
+ options["verbose"] = v
37
+ end
38
+ op.on "-h", "--help", "Show this message" do
39
+ puts op
40
+ exit
41
+ end
42
+ op.on "--version" do
43
+ puts Envoy::VERSION
44
+ exit
45
+ end
46
+ op.parse!
47
+ case ARGV[0]
48
+ when /^(\d+)$/
49
+ options["local_port"] = $1
50
+ when /^(\[[^\]+]\]|[^:]+):(\d+)$/x
51
+ options["local_host"] = $1
52
+ options["local_port"] = $2
53
+ when /^(.*)$/
54
+ options["local_host"] = $1
55
+ end
56
+ end
57
+ options
58
+ end
59
+
@@ -42,11 +42,15 @@ module Envoy
42
42
  def receive_keepalive
43
43
  end
44
44
 
45
- def receive_message message
45
+ def log message
46
46
  t = Time.now.strftime("%F %T")
47
47
  STDERR.puts t + " " + message.split("\n").join("\n#{t.gsub(/./, ' ')} ")
48
48
  end
49
49
 
50
+ def receive_message message
51
+ log message
52
+ end
53
+
50
54
  def receive_halt
51
55
  @halting = true
52
56
  EventMachine.stop_event_loop
@@ -84,4 +88,4 @@ module Envoy
84
88
  end
85
89
 
86
90
  end
87
- end
91
+ end
@@ -30,3 +30,4 @@ module Envoy
30
30
 
31
31
  end
32
32
  end
33
+
@@ -11,7 +11,18 @@ module Envoy
11
11
  @connection = "close"
12
12
  end
13
13
 
14
+ def send_page status, message
15
+ send_data "HTTP/1.0 #{status} Message\r\n"
16
+ send_data "Content-Type: text/plain\r\n"
17
+ send_data "\r\n"
18
+ send_data "#{message}\r\n"
19
+ end
20
+
14
21
  def close code
22
+ case code
23
+ when 502
24
+ send_page code, "The service isn't running, and couldn't be started."
25
+ end
15
26
  close_connection(true)
16
27
  end
17
28
 
@@ -42,10 +53,7 @@ module Envoy
42
53
  @header << line + "\r\n"
43
54
  end
44
55
  rescue RuntimeError => e
45
- send_data "HTTP/1.0 500 Internal Server Error\r\n"
46
- send_data "Content-Type: text/plain\r\n"
47
- send_data "\r\n"
48
- send_data "#{e.message}\r\n"
56
+ send_page 500, e.inspect
49
57
  close_connection true
50
58
  end
51
59
 
@@ -1,3 +1,3 @@
1
1
  module Envoy
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envoy-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Baum
@@ -85,6 +85,7 @@ files:
85
85
  - envoy-proxy.gemspec
86
86
  - lib/envoy/client/channel.rb
87
87
  - lib/envoy/client/command.rb
88
+ - lib/envoy/client/option_parser.rb
88
89
  - lib/envoy/client/trunk.rb
89
90
  - lib/envoy/protocol.rb
90
91
  - lib/envoy/server/channel.rb