136 lines
4.3 KiB
Ruby
136 lines
4.3 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/v5.3.2.tar.gz"
|
|
sha256 "f92e184507bee9717336400b0717faf269abcfabe44af6fbb4273df00dc8942d"
|
|
head "https://github.com/grafana/grafana.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "a42424ac58bfe97afd7dc850c60bf0e974ed576350d11778b2696f605df32a73" => :mojave
|
|
sha256 "17fee26fa1176eb58b44c3ae690d5fa038454ca987f5e60c87c4b2b4eeaaae34" => :high_sierra
|
|
sha256 "c8512abf229870dbaf8761963fd0b3572d98fef60ecfd1f918443562a8626c7d" => :sierra
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "node" => :build
|
|
depends_on "yarn" => :build
|
|
|
|
def install
|
|
ENV["GOPATH"] = buildpath
|
|
grafana_path = buildpath/"src/github.com/grafana/grafana"
|
|
grafana_path.install buildpath.children
|
|
|
|
cd grafana_path do
|
|
system "go", "run", "build.go", "build"
|
|
|
|
system "yarn", "install", "--ignore-engines"
|
|
|
|
args = ["build"]
|
|
# Avoid PhantomJS error "unrecognized selector sent to instance"
|
|
args << "--force" unless build.bottle?
|
|
system "node_modules/grunt-cli/bin/grunt", *args
|
|
|
|
bin.install "bin/darwin-amd64/grafana-cli"
|
|
bin.install "bin/darwin-amd64/grafana-server"
|
|
(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", "vendor"
|
|
prefix.install_metafiles
|
|
end
|
|
end
|
|
|
|
def post_install
|
|
(var/"log/grafana").mkpath
|
|
(var/"lib/grafana/plugins").mkpath
|
|
end
|
|
|
|
plist_options :manual => "grafana-server --config=#{HOMEBREW_PREFIX}/etc/grafana/grafana.ini --homepath #{HOMEBREW_PREFIX}/share/grafana cfg:default.paths.logs=#{HOMEBREW_PREFIX}/var/log/grafana cfg:default.paths.data=#{HOMEBREW_PREFIX}/var/lib/grafana cfg:default.paths.plugins=#{HOMEBREW_PREFIX}/var/lib/grafana/plugins"
|
|
|
|
def plist; <<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>KeepAlive</key>
|
|
<dict>
|
|
<key>SuccessfulExit</key>
|
|
<false/>
|
|
</dict>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_bin}/grafana-server</string>
|
|
<string>--config</string>
|
|
<string>#{etc}/grafana/grafana.ini</string>
|
|
<string>--homepath</string>
|
|
<string>#{opt_pkgshare}</string>
|
|
<string>cfg:default.paths.logs=#{var}/log/grafana</string>
|
|
<string>cfg:default.paths.data=#{var}/lib/grafana</string>
|
|
<string>cfg:default.paths.plugins=#{var}/lib/grafana/plugins</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>WorkingDirectory</key>
|
|
<string>#{var}/lib/grafana</string>
|
|
<key>StandardErrorPath</key>
|
|
<string>#{var}/log/grafana/grafana-stderr.log</string>
|
|
<key>StandardOutPath</key>
|
|
<string>#{var}/log/grafana/grafana-stdout.log</string>
|
|
<key>SoftResourceLimits</key>
|
|
<dict>
|
|
<key>NumberOfFiles</key>
|
|
<integer>10240</integer>
|
|
</dict>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
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(5) do
|
|
li = false
|
|
r.each do |l|
|
|
if l =~ /Initializing HTTPServer/
|
|
li = true
|
|
break
|
|
end
|
|
end
|
|
li
|
|
end
|
|
|
|
Process.kill("TERM", pid)
|
|
w.close
|
|
r.close
|
|
listening
|
|
end
|
|
end
|