class Grafana < Formula desc "Gorgeous metric visualizations and dashboards for timeseries databases" homepage "https://grafana.com" url "https://github.com/grafana/grafana/archive/v6.4.2.tar.gz" sha256 "28f961f7b2c68e5961561fca99dd02a03382503a6179df9b62487df2501e171f" head "https://github.com/grafana/grafana.git" bottle do cellar :any_skip_relocation sha256 "bf0ce0c112edd78c98e4c2cb8ba38865a34507c40b715f12644c765cb1119bb8" => :catalina sha256 "3d75defcbe595370ef611011062649e496d77fef9b79d26af0ee4101dc8cbef4" => :mojave sha256 "eab444f297fc4adee8379ff13c859427110cb20c0a168c12ad1ead1c91f6b6eb" => :high_sierra end depends_on "go@1.12" => :build depends_on "node@10" => :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" system "node_modules/grunt-cli/bin/grunt", "build" 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 --packaging=brew 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 KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{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 RunAtLoad WorkingDirectory #{var}/lib/grafana StandardErrorPath #{var}/log/grafana/grafana-stderr.log StandardOutPath #{var}/log/grafana/grafana-stdout.log SoftResourceLimits NumberOfFiles 10240 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 HTTPServer/.match?(l) li = true break end end li end Process.kill("TERM", pid) w.close r.close listening end end