homebrew-core/Formula/kapacitor.rb

104 lines
3.7 KiB
Ruby

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.6.4",
revision: "dfdea23b82343fca1976358b9d98cd8ec42e09df"
license "MIT"
head "https://github.com/influxdata/kapacitor.git", branch: "master"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "f32e511a348e8c377099aa9fdfc56d628d35bb5252c586416e0d2d6ccab0be24"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "c17b8196f8b873bf5c92e71f10fca6d24858e2c8d9100f6acca6191e87f4cb41"
sha256 cellar: :any_skip_relocation, monterey: "d64fcd22b98c4747c4aeaf025fe4dd644368153229bbe97176248caa436ecc7c"
sha256 cellar: :any_skip_relocation, big_sur: "6306917a076b5caaf5234d7d5063b3aa6d4f670f35c635581611222a0b09863f"
sha256 cellar: :any_skip_relocation, catalina: "40a1d991e84eb1c7dfcdc6e59c9c30f66bde65f6bb2dab263bfd598777d82cc6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "7ba7eb7269f6445c7d20bdcd5710011d121b253d527fa96c09f3e16c1fec03bc"
end
depends_on "go" => :build
depends_on "rust" => :build
on_linux do
depends_on "pkg-config" => :build # for `pkg-config-wrapper`
end
# NOTE: The version here is specified in the go.mod of kapacitor.
# If you're upgrading to a newer kapacitor version, check to see if this needs upgraded too.
resource "pkg-config-wrapper" do
url "https://github.com/influxdata/pkg-config/archive/v0.2.11.tar.gz"
sha256 "52b22c151163dfb051fd44e7d103fc4cde6ae8ff852ffc13adeef19d21c36682"
end
def install
resource("pkg-config-wrapper").stage do
system "go", "build", *std_go_args, "-o", buildpath/"bootstrap/pkg-config"
end
ENV.prepend_path "PATH", buildpath/"bootstrap"
ldflags = %W[
-s
-w
-X main.version=#{version}
-X main.commit=#{Utils.git_head}
]
system "go", "build", *std_go_args(ldflags: ldflags.join(" ")), "./cmd/kapacitor"
system "go", "build", *std_go_args(ldflags: ldflags.join(" ")), "-o", bin/"kapacitord", "./cmd/kapacitord"
inreplace "etc/kapacitor/kapacitor.conf" do |s|
s.gsub! "/var/lib/kapacitor", "#{var}/kapacitor"
s.gsub! "/var/log/kapacitor", "#{var}/log"
end
etc.install "etc/kapacitor/kapacitor.conf" => "kapacitor.conf"
end
def post_install
(var/"kapacitor/replay").mkpath
(var/"kapacitor/tasks").mkpath
end
service do
run [opt_bin/"kapacitord", "-config", etc/"kapacitor.conf"]
keep_alive successful_exit: false
error_log_path var/"log/kapacitor.log"
log_path var/"log/kapacitor.log"
working_dir var
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
http_port = free_port
ENV["KAPACITOR_URL"] = "http://localhost:#{http_port}"
ENV["KAPACITOR_HTTP_BIND_ADDRESS"] = ":#{http_port}"
ENV["KAPACITOR_INFLUXDB_0_ENABLED"] = "false"
ENV["KAPACITOR_REPORTING_ENABLED"] = "false"
begin
pid = fork do
exec "#{bin}/kapacitord -config #{testpath}/config.toml"
end
sleep 20
shell_output("#{bin}/kapacitor list tasks")
ensure
Process.kill("SIGINT", pid)
Process.wait(pid)
end
end
end