class Kapacitor < Formula desc "Open source time series data processor" homepage "https://github.com/influxdata/kapacitor" url "https://github.com/influxdata/kapacitor.git", :tag => "v1.3.0", :revision => "7e27fd070e6a629a9b760c6300fade41364f4c7f" head "https://github.com/influxdata/kapacitor.git" bottle do sha256 "53c463f47251fe07c4ca040b32b5bdb14bdcb2d337f842794974546c4c5ffda3" => :sierra sha256 "111b019fdae9c83c3ac8820464e8cc7c1e3de77d4645612e29663212a2840448" => :el_capitan sha256 "e703c4f37e2f22371e474f3be048238ce308e233d10f3097e3c5d7a442f4c5a7" => :yosemite end depends_on "go" => :build def install ENV["GOPATH"] = buildpath kapacitor_path = buildpath/"src/github.com/influxdata/kapacitor" kapacitor_path.install Dir["*"] revision = `git rev-parse HEAD`.strip version = `git describe --tags`.strip cd kapacitor_path do system "go", "install", "-ldflags", "-X main.version=#{version} -X main.commit=#{revision}", "./cmd/..." end inreplace kapacitor_path/"etc/kapacitor/kapacitor.conf" do |s| s.gsub! "/var/lib/kapacitor", "#{var}/kapacitor" s.gsub! "/var/log/kapacitor", "#{var}/log" end bin.install "bin/kapacitord" bin.install "bin/kapacitor" etc.install kapacitor_path/"etc/kapacitor/kapacitor.conf" => "kapacitor.conf" (var/"kapacitor/replay").mkpath (var/"kapacitor/tasks").mkpath end plist_options :manual => "kapacitord -config #{HOMEBREW_PREFIX}/etc/kapacitor.conf" def plist; <<-EOS.undent KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{opt_bin}/kapacitord -config #{HOMEBREW_PREFIX}/etc/kapacitor.conf RunAtLoad WorkingDirectory #{var} StandardErrorPath #{var}/log/kapacitor.log StandardOutPath #{var}/log/kapacitor.log EOS end test do (testpath/"config.toml").write shell_output("#{bin}/kapacitord config") inreplace testpath/"config.toml" do |s| s.gsub! /disable-subscriptions = false/, "disable-subscriptions = true" s.gsub! %r{data_dir = "/.*/.kapacitor"}, "data_dir = \"#{testpath}/kapacitor\"" s.gsub! %r{/.*/.kapacitor/replay}, "#{testpath}/kapacitor/replay" s.gsub! %r{/.*/.kapacitor/tasks}, "#{testpath}/kapacitor/tasks" s.gsub! %r{/.*/.kapacitor/kapacitor.db}, "#{testpath}/kapacitor/kapacitor.db" end begin pid = fork do exec "#{bin}/kapacitord -config #{testpath}/config.toml" end sleep 2 shell_output("#{bin}/kapacitor list tasks") ensure Process.kill("SIGINT", pid) Process.wait(pid) end end end