class Linkerd < Formula desc "Drop-in RPC proxy designed for microservices" homepage "https://linkerd.io/" url "https://github.com/linkerd/linkerd/releases/download/1.4.6/linkerd-1.4.6.tgz" sha256 "0292b1ac2e8010bc6592d05b14efb088b2b092533219807bbf6f3a24e37518ca" bottle :unneeded depends_on :java => "1.8+" def install inreplace "config/linkerd.yaml", "disco", etc/"linkerd/disco" libexec.install "linkerd-#{version}-exec" bin.install_symlink libexec/"linkerd-#{version}-exec" => "linkerd" pkgshare.install buildpath/"config/linkerd.yaml" => "default.yaml" etc.install "config" => "linkerd" etc.install "disco" => "linkerd/disco" libexec.install_symlink etc/"linkerd" => "config" libexec.install_symlink etc/"linkerd/disco" => "disco" share.install "docs" end def post_install (var/"log/linkerd").mkpath end plist_options :manual => "linkerd #{HOMEBREW_PREFIX}/etc/linkerd/linkerd.yaml" def plist; <<~EOS Label #{plist_name} WorkingDirectory #{HOMEBREW_PREFIX} ProgramArguments #{opt_bin}/linkerd #{etc}/linkerd/linkerd.yaml RunAtLoad KeepAlive StandardErrorPath #{var}/log/linkerd/linkerd.log StandardOutPath #{var}/log/linkerd/linkerd.log EOS end test do (testpath/"index.html").write "It works!" simple_http_pid = fork do exec "python -m SimpleHTTPServer 9999" end linkerd_pid = fork do exec "#{bin}/linkerd #{pkgshare}/default.yaml" end sleep 10 begin assert_match "It works!", shell_output("curl -s -H 'Host: web' http://localhost:4140") assert_match "Bad Gateway", shell_output("curl -s -I -H 'Host: foo' http://localhost:4140") ensure Process.kill("TERM", linkerd_pid) Process.wait(linkerd_pid) Process.kill("TERM", simple_http_pid) Process.wait(simple_http_pid) end end end