homebrew-core/Formula/fabio.rb

73 lines
2 KiB
Ruby
Raw Normal View History

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.2.tar.gz"
sha256 "b01f0dc0a299ffd8d9f386783646e6782701609b7ede63e060e37ccad5a50bde"
head "https://github.com/eBay/fabio.git"
2016-02-17 18:06:23 +00:00
bottle do
cellar :any_skip_relocation
2016-07-16 09:22:59 +00:00
sha256 "adf99018f03fb127768a7fafdb2a91f95a3eec745d0d1b40519d0c130ae4e6e7" => :el_capitan
sha256 "bf4da8915b249a46278d63fa68d2c123d4af622f72835a02b7714f09edd10022" => :yosemite
sha256 "6f493cd9615ed33280893b2d575c5c3cec75de0c18a0d1a6b66866afe06eecee" => :mavericks
2016-02-17 18:06:23 +00:00
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
2016-07-14 03:02:31 +00:00
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