72 lines
2 KiB
Ruby
72 lines
2 KiB
Ruby
class Fabio < Formula
|
|
desc "Zero-conf load balancing HTTP(S) router"
|
|
homepage "https://github.com/eBay/fabio"
|
|
url "https://github.com/eBay/fabio/archive/v1.4.1.tar.gz"
|
|
sha256 "7ca28cc76bfe3cf2705adc29eca77e328d5fd5c94fa453eb26fd961d04881efe"
|
|
head "https://github.com/eBay/fabio.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "a738ddbe3d2505295c4344020ca5bb75c75baa381476a152e7e1847f5e09401c" => :sierra
|
|
sha256 "f113058f4a28c7d7d3b3f7beab84d74c37db27ac3c1ff171a1f3d01da910de79" => :el_capitan
|
|
sha256 "4308e422089f1611a26ed4a88c9b51d5b0767b0f6f53d09a44c31dd37dec3d74" => :yosemite
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "consul" => :recommended
|
|
|
|
def install
|
|
mkdir_p buildpath/"src/github.com/eBay"
|
|
ln_s buildpath, buildpath/"src/github.com/eBay/fabio"
|
|
|
|
ENV["GOPATH"] = buildpath.to_s
|
|
|
|
system "go", "install", "github.com/eBay/fabio"
|
|
bin.install "#{buildpath}/bin/fabio"
|
|
end
|
|
|
|
test do
|
|
require "socket"
|
|
require "timeout"
|
|
|
|
CONSUL_DEFAULT_PORT = 8500
|
|
FABIO_DEFAULT_PORT = 9999
|
|
LOCALHOST_IP = "127.0.0.1".freeze
|
|
|
|
def port_open?(ip, port, seconds = 1)
|
|
Timeout.timeout(seconds) do
|
|
begin
|
|
TCPSocket.new(ip, port).close
|
|
true
|
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
|
false
|
|
end
|
|
end
|
|
rescue Timeout::Error
|
|
false
|
|
end
|
|
|
|
if !port_open?(LOCALHOST_IP, FABIO_DEFAULT_PORT)
|
|
if !port_open?(LOCALHOST_IP, CONSUL_DEFAULT_PORT)
|
|
fork do
|
|
exec "consul agent -dev -bind 127.0.0.1"
|
|
puts "consul started"
|
|
end
|
|
sleep 15
|
|
else
|
|
puts "Consul already running"
|
|
end
|
|
fork do
|
|
exec "#{bin}/fabio &>fabio-start.out&"
|
|
puts "fabio started"
|
|
end
|
|
sleep 5
|
|
assert_equal true, port_open?(LOCALHOST_IP, FABIO_DEFAULT_PORT)
|
|
system "killall", "fabio" # fabio forks off from the fork...
|
|
system "consul", "leave"
|
|
else
|
|
puts "Fabio already running or Consul not available or starting fabio failed."
|
|
false
|
|
end
|
|
end
|
|
end
|