falcon 0.34.5 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/Gemfile +2 -0
  4. data/bin/falcon +1 -1
  5. data/bin/falcon-host +1 -1
  6. data/examples/beer/config.ru +25 -23
  7. data/examples/beer/falcon.rb +2 -0
  8. data/examples/hello/config.ru +1 -1
  9. data/examples/hello/falcon.rb +14 -2
  10. data/examples/hello/preload.rb +6 -0
  11. data/examples/trailers/config.ru +33 -0
  12. data/examples/trailers/falcon.rb +7 -0
  13. data/falcon.gemspec +3 -1
  14. data/lib/falcon.rb +0 -4
  15. data/lib/falcon/adapters/response.rb +2 -2
  16. data/lib/falcon/command.rb +3 -53
  17. data/lib/falcon/command/host.rb +22 -39
  18. data/lib/falcon/command/paths.rb +45 -0
  19. data/lib/falcon/{host.rb → command/proxy.rb} +39 -45
  20. data/lib/falcon/command/redirect.rb +72 -0
  21. data/lib/falcon/command/serve.rb +28 -58
  22. data/lib/falcon/command/supervisor.rb +5 -5
  23. data/lib/falcon/command/top.rb +79 -0
  24. data/lib/falcon/command/virtual.rb +18 -53
  25. data/lib/falcon/configuration.rb +1 -1
  26. data/lib/falcon/{configurations/host.rb → configuration/application.rb} +13 -11
  27. data/lib/falcon/{configurations → configuration}/lets_encrypt_tls.rb +0 -0
  28. data/lib/falcon/{configurations → configuration}/proxy.rb +2 -2
  29. data/lib/falcon/{configurations → configuration}/rack.rb +2 -2
  30. data/lib/falcon/{configurations → configuration}/self_signed_tls.rb +0 -0
  31. data/lib/falcon/{configurations → configuration}/supervisor.rb +2 -2
  32. data/lib/falcon/{configurations → configuration}/tls.rb +0 -0
  33. data/lib/falcon/controller/host.rb +58 -0
  34. data/lib/falcon/controller/proxy.rb +102 -0
  35. data/lib/falcon/{service.rb → controller/redirect.rb} +37 -24
  36. data/lib/falcon/controller/serve.rb +112 -0
  37. data/lib/falcon/controller/virtual.rb +89 -0
  38. data/lib/falcon/middleware/proxy.rb +143 -0
  39. data/lib/falcon/{redirection.rb → middleware/redirect.rb} +31 -29
  40. data/lib/falcon/proxy_endpoint.rb +1 -1
  41. data/lib/falcon/service/application.rb +113 -0
  42. data/lib/falcon/service/generic.rb +53 -0
  43. data/lib/falcon/service/supervisor.rb +95 -0
  44. data/lib/falcon/services.rb +32 -5
  45. data/lib/falcon/version.rb +1 -1
  46. data/lib/rack/handler/falcon.rb +2 -1
  47. data/logo-square.afdesign +0 -0
  48. metadata +43 -17
  49. data/lib/falcon/hosts.rb +0 -135
  50. data/lib/falcon/proxy.rb +0 -141
  51. data/lib/falcon/supervisor.rb +0 -106
@@ -1,106 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'async/io/endpoint'
22
-
23
- require_relative 'proxy'
24
- require_relative 'redirection'
25
-
26
- require 'async/container'
27
- require 'async/container/controller'
28
- require 'async/http/endpoint'
29
-
30
- module Falcon
31
- class Supervisor
32
- class Statistics
33
- PS = "ps"
34
-
35
- def initialize(pgid: Process.ppid, ps: PS)
36
- @ppid = pgid
37
- @ps = ps
38
- end
39
-
40
- # pid: Process Identifier
41
- # pmem: Percentage Memory used.
42
- # pcpu: Percentage Processor used.
43
- # time: The process time used (executing on CPU).
44
- # vsz: Virtual Size in kilobytes
45
- # rss: Resident Set Size in kilobytes
46
- # etime: The process elapsed time.
47
- # command: The name of the process.
48
- COLUMNS = "pid,pmem,pcpu,time,vsz,rss,etime,command"
49
-
50
- def capture
51
- input, output = IO.pipe
52
-
53
- system(@ps, "--ppid", @ppid.to_s, "-o", COLUMNS, out: output, pgroup: true)
54
- output.close
55
-
56
- header, *lines = input.readlines.map(&:strip)
57
-
58
- keys = header.split(/\s+/).map(&:downcase)
59
-
60
- processes = lines.map do |line|
61
- keys.zip(line.split(/\s+/, keys.size)).to_h
62
- end
63
-
64
- return processes
65
- end
66
- end
67
-
68
- def initialize(endpoint)
69
- @endpoint = endpoint
70
- end
71
-
72
- def restart(message)
73
- signal = message[:signal] || :INT
74
-
75
- # Sepukku:
76
- Process.kill(signal, -Process.getpgrp)
77
- end
78
-
79
- def statistics(message)
80
- statistics = Statistics.new
81
-
82
- statistics.capture
83
- end
84
-
85
- def handle(message)
86
- case message[:please]
87
- when 'restart'
88
- self.restart(message)
89
- when 'statistics'
90
- self.statistics(message)
91
- end
92
- end
93
-
94
- def run
95
- Async.logger.info("Binding to #{@endpoint}")
96
- @endpoint.accept do |peer|
97
- stream = Async::IO::Stream.new(peer)
98
-
99
- while message = stream.gets("\0")
100
- response = handle(JSON.parse(message, symbolize_names: true))
101
- stream.puts(response.to_json, separator: "\0")
102
- end
103
- end
104
- end
105
- end
106
- end