2016-02-15 08:43:40 +00:00
|
|
|
class Fabio < Formula
|
2016-09-09 22:11:54 +00:00
|
|
|
desc "Zero-conf load balancing HTTP(S) router"
|
2016-02-15 08:43:40 +00:00
|
|
|
homepage "https://github.com/eBay/fabio"
|
2016-09-11 19:15:19 +00:00
|
|
|
url "https://github.com/eBay/fabio/archive/v1.3.2.tar.gz"
|
|
|
|
sha256 "2f8b8451c83b6c72b6d5365e4cb1eddc3e8d45938b53f1d24f74fe8760d539ae"
|
2016-02-15 08:43:40 +00:00
|
|
|
head "https://github.com/eBay/fabio.git"
|
|
|
|
|
2016-02-17 18:06:23 +00:00
|
|
|
bottle do
|
|
|
|
cellar :any_skip_relocation
|
2016-09-27 17:58:50 +00:00
|
|
|
sha256 "ab9a62cc29321f672022f51015605db1183699a1339df16d30bcd8944e7dfb41" => :sierra
|
2016-09-11 23:30:06 +00:00
|
|
|
sha256 "0ac98d351c614b80e2dc01a2bd23da313709ba715c43dad6f3801e416bc1e123" => :el_capitan
|
|
|
|
sha256 "0edc187ea6ab4064a709bad24048026f21ef49ff2e8c36a7e77764aa94b899dd" => :yosemite
|
|
|
|
sha256 "c46038cecf11239216443dba458864da3af8ffea5a95f9ae953d75721b9f3d93" => :mavericks
|
2016-02-17 18:06:23 +00:00
|
|
|
end
|
|
|
|
|
2016-02-15 08:43:40 +00:00
|
|
|
depends_on "go" => :build
|
|
|
|
depends_on "consul" => :recommended
|
|
|
|
|
|
|
|
def install
|
2016-07-11 19:45:46 +00:00
|
|
|
mkdir_p buildpath/"src/github.com/eBay"
|
|
|
|
ln_s buildpath, buildpath/"src/github.com/eBay/fabio"
|
2016-02-15 08:43:40 +00:00
|
|
|
|
2016-07-11 19:45:46 +00:00
|
|
|
ENV["GOPATH"] = buildpath.to_s
|
2016-02-15 08:43:40 +00:00
|
|
|
|
2016-07-11 19:45:46 +00:00
|
|
|
system "go", "install", "github.com/eBay/fabio"
|
|
|
|
bin.install "#{buildpath}/bin/fabio"
|
2016-02-15 08:43:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test do
|
2016-07-14 03:02:31 +00:00
|
|
|
require "socket"
|
|
|
|
require "timeout"
|
|
|
|
|
2016-09-09 22:11:54 +00:00
|
|
|
CONSUL_DEFAULT_PORT = 8500
|
|
|
|
FABIO_DEFAULT_PORT = 9999
|
|
|
|
LOCALHOST_IP = "127.0.0.1".freeze
|
2016-02-15 08:43:40 +00:00
|
|
|
|
|
|
|
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
|