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.4.1", :revision => "b05bb0f6be089d6a1a391867ad4020344ce42a53" head "https://github.com/influxdata/kapacitor.git" bottle do cellar :any_skip_relocation sha256 "cea8c73229b3ddfc68ed1f11d4c53a625604f6db532b3ec62b1b0964d2cffb39" => :high_sierra sha256 "34deafa5e72e360424d2be3db71303bfc5ff2e4f98232370f200d254b007ae6f" => :sierra sha256 "060e3b452c09f6e66c5ab90da292ed98b244a95b2ddba1bcbdac0ec0bfc14f24" => :el_capitan 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 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