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 cellar :any_skip_relocation sha256 "72dfd565d092dc4637ce7da475210e52a06322550876d5f7670ae52c3118bbc3" => :sierra sha256 "8cf8027f5bf26fcecd16a1ee7965eb7f15e331531dcbdf8e14f06e9179f7f192" => :el_capitan sha256 "867ba9f2cbf689b329f2b0d992306667a75024863e1888d850107d2dfe45082e" => :yosemite 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 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 HTTP Server/ li = true break end end li end Process.kill("TERM", pid) w.close r.close listening end end