homebrew-core/Formula/grafana.rb

114 lines
3.5 KiB
Ruby

class Grafana < Formula
desc "Gorgeous metric visualizations and dashboards for timeseries databases"
homepage "https://grafana.com"
url "https://github.com/grafana/grafana/archive/v9.1.7.tar.gz"
sha256 "dac3d154901a9d5e0d1a21f3b3a5b06ea62e86aa03c4e2fa1fe38257887f3439"
license "AGPL-3.0-only"
head "https://github.com/grafana/grafana.git", branch: "main"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "f2ff299a2bbf7694a993c42c881a5faf9a842596579f9ee208ba113cb0126c29"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "08e361a993894ceb08b33486759d21f95c2a8250a05a39780b24c1d926d77e7d"
sha256 cellar: :any_skip_relocation, monterey: "9087f8e1f0f79cd61fe2ae8cd632495aa8876eb6824739e87a8cadd7f8644309"
sha256 cellar: :any_skip_relocation, big_sur: "a0b94b07df96c0cad8d0024b73f6628dfc1db54d0ad10ca2535ee3e2ac13ac5c"
sha256 cellar: :any_skip_relocation, catalina: "33471542c78dd08dc47ce89c7586605e64a8872739d2bc26e662f3103b4ec85d"
sha256 cellar: :any_skip_relocation, x86_64_linux: "9b29940cc6e11ba1c3ff72d23101e019629879261ecca356359b6e629745933a"
end
depends_on "go" => :build
depends_on "node@16" => :build
depends_on "yarn" => :build
uses_from_macos "zlib"
on_linux do
depends_on "fontconfig"
depends_on "freetype"
end
def install
ENV["NODE_OPTIONS"] = "--max-old-space-size=8000"
system "make", "gen-go"
system "go", "run", "build.go", "build"
system "yarn", "install"
system "yarn", "build"
if OS.mac?
bin.install Dir["bin/darwin-*/grafana-cli"]
bin.install Dir["bin/darwin-*/grafana-server"]
else
bin.install "bin/linux-amd64/grafana-cli"
bin.install "bin/linux-amd64/grafana-server"
end
(etc/"grafana").mkpath
cp("conf/sample.ini", "conf/grafana.ini.example")
etc.install "conf/sample.ini" => "grafana/grafana.ini"
etc.install "conf/grafana.ini.example" => "grafana/grafana.ini.example"
pkgshare.install "conf", "public", "tools"
end
def post_install
(var/"log/grafana").mkpath
(var/"lib/grafana/plugins").mkpath
end
service do
run [opt_bin/"grafana-server",
"--config", etc/"grafana/grafana.ini",
"--homepath", opt_pkgshare,
"--packaging=brew",
"cfg:default.paths.logs=#{var}/log/grafana",
"cfg:default.paths.data=#{var}/lib/grafana",
"cfg:default.paths.plugins=#{var}/lib/grafana/plugins"]
keep_alive true
error_log_path var/"log/grafana-stderr.log"
log_path var/"log/grafana-stdout.log"
working_dir var/"lib/grafana"
end
test do
require "pty"
require "timeout"
# first test
system bin/"grafana-server", "-v"
# avoid stepping on anything that may be present in this directory
tdir = File.join(Dir.pwd, "grafana-test")
Dir.mkdir(tdir)
logdir = File.join(tdir, "log")
datadir = File.join(tdir, "data")
plugdir = File.join(tdir, "plugins")
[logdir, datadir, plugdir].each do |d|
Dir.mkdir(d)
end
Dir.chdir(pkgshare)
res = PTY.spawn(bin/"grafana-server",
"cfg:default.paths.logs=#{logdir}",
"cfg:default.paths.data=#{datadir}",
"cfg:default.paths.plugins=#{plugdir}",
"cfg:default.server.http_port=50100")
r = res[0]
w = res[1]
pid = res[2]
listening = Timeout.timeout(10) do
li = false
r.each do |l|
if /HTTP Server Listen/.match?(l)
li = true
break
end
end
li
end
Process.kill("TERM", pid)
w.close
r.close
listening
end
end