/
fabio.rb
67 lines (59 loc) 路 2.57 KB
/
fabio.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Fabio < Formula
desc "Zero-conf load balancing HTTP(S) router"
homepage "https://github.com/fabiolb/fabio"
url "https://github.com/fabiolb/fabio/archive/refs/tags/v1.6.3.tar.gz"
sha256 "e85b70a700652b051260b8c49ce63d21d2579517601a91d893a7fa9444635ad3"
license "MIT"
head "https://github.com/fabiolb/fabio.git", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, arm64_sonoma: "e4a20558083c013910f2d092982c75243b8a358b1599fc75a1b18de6890d9526"
sha256 cellar: :any_skip_relocation, arm64_ventura: "ab8990ed9eeab8dee4b314bcb6189d50f4dc8eebee77de71bc496d4bf8c78b9b"
sha256 cellar: :any_skip_relocation, arm64_monterey: "93816978aba8f3872e86a77f0ccf1965d92d7377389af58fa12a58c97f23033c"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f6bbd95332e4477f3dab83ab33e4ea0eefe9a5545d24b25388e435a14a6baba"
sha256 cellar: :any_skip_relocation, sonoma: "e034f62a86f59035c2bf31563214cc76234336f4ee9c5d6f049f8659c1d508aa"
sha256 cellar: :any_skip_relocation, ventura: "f05450e71e0044473f85a289d549277edede0d51166a66ff985465f826290d6f"
sha256 cellar: :any_skip_relocation, monterey: "ee9fa30859ec7a0e89cd3725759d6f57d039f6a36529abaca6dea2c5d22a163a"
sha256 cellar: :any_skip_relocation, big_sur: "ca2de624dcf98c51943d3968c19bbf6fd5e4211826b29eadff3a9bde4d4ace45"
sha256 cellar: :any_skip_relocation, x86_64_linux: "ee9395e3877ab2abdaa6dddba8405241ca30ce5c0ae56eada5b01e15cdb37382"
end
deprecate! date: "2024-02-04", because: "depends on soon to be deprecated consul"
depends_on "go" => :build
depends_on "consul"
def install
system "go", "build", *std_go_args(ldflags: "-s -w")
end
def port_open?(ip_address, port, seconds = 1)
Timeout.timeout(seconds) do
TCPSocket.new(ip_address, port).close
end
true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Timeout::Error
false
end
test do
require "socket"
require "timeout"
consul_default_port = 8500
fabio_default_port = 9999
localhost_ip = "127.0.0.1".freeze
if port_open?(localhost_ip, fabio_default_port)
puts "Fabio already running or Consul not available or starting fabio failed."
false
else
if port_open?(localhost_ip, consul_default_port)
puts "Consul already running"
else
fork do
exec "consul agent -dev -bind 127.0.0.1"
end
sleep 30
end
fork do
exec "#{bin}/fabio"
end
sleep 10
assert_equal true, port_open?(localhost_ip, fabio_default_port)
system "consul", "leave"
end
end
end