class Grafana < Formula desc "Gorgeous metric visualizations and dashboards for timeseries databases" homepage "https://grafana.com" url "https://github.com/grafana/grafana/archive/v5.2.3.tar.gz" sha256 "f65668e8524219e5733e310574b40530f21357076879c11daed74fd4fc018aa7" head "https://github.com/grafana/grafana.git" bottle do cellar :any_skip_relocation sha256 "037c93ae40e1bdb0b50ae97a7f5fc9be25f7ddfd0e40f99eb6ad0af8835c858d" => :mojave sha256 "75437195866668bcf5c27a14d780785d8e7dc56250bde18fbb9d2725533c877f" => :high_sierra sha256 "239cb98d2bd797dd77d135a7a3c378eddb46168f38a74315c20c36a1ef2ba8aa" => :sierra sha256 "e816a8bcf5853521265f7fce67eaaadab250924e10c7590e2edff3d35f6cdb9b" => :el_capitan 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 KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{opt_bin}/grafana-server --config #{etc}/grafana/grafana.ini --homepath #{opt_pkgshare} 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 l =~ /Initializing HTTPServer/ li = true break end end li end Process.kill("TERM", pid) w.close r.close listening end end