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.0.1", :revision => "04f1ab3116b6bab27cbf63cb0e6b918fc77c7320" head "https://github.com/influxdata/kapacitor.git" bottle do cellar :any_skip_relocation sha256 "e86d8e487a22692d980ecd18f953e6ee3e8d6b5d20c7a669bc78596e375aad7f" => :sierra sha256 "e38b8a9fe9679f98aaf818f9a6ad9b77db05837ce6191b96f9f327ef5d231c87" => :el_capitan sha256 "a24c21e3c44fda7f6cd95c9b14090be357e29e750839bee2f6b8ee628a99b28b" => :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("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