forked from grafana/homebrew-grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grafana.rb
139 lines (121 loc) · 4.51 KB
/
grafana.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# typed: false
# frozen_string_literal: true
require "language/node"
class Grafana < Formula
desc "Gorgeous metric visualizations and dashboards for timeseries databases"
homepage "https://grafana.com"
url "https://github.com/grafana/grafana/archive/v4.3.0.tar.gz"
sha256 "d81e5fdb7ac702646a4b17343796970c91000ea5ea2036880e0e3e36c7a0a8a5"
head "https://github.com/grafana/grafana.git"
bottle do
sha256 cellar: :any_skip_relocation, sierra: "7c7bcf3fa6db1c54dc94ab030ac0c8adc3d20761e695446ba13c1db98c6568d4"
sha256 cellar: :any_skip_relocation, el_capitan: "96f30bf66355d985b23b39d2466f23e6a83455a4c9a1b9479eefaacc6415ef64"
sha256 cellar: :any_skip_relocation, yosemite: "41b6bca25925ab369383de74667e0b2ed5a79db8003ff3f3b82c73eeab5d047e"
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"
system "npm", "install", "grunt-cli", *Language::Node.local_npm_install_args
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/grafana-cli"
bin.install "bin/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", "vendor"
pkgshare.install "public_gen" => "public"
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.undent
<?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 /Initializing HTTP Server/.match?(l)
li = true
break
end
end
li
end
Process.kill("TERM", pid)
w.close
r.close
listening
end
end