class Influxdb < Formula desc "Time series, events, and metrics database" homepage "https://influxdata.com/time-series-platform/influxdb/" url "https://github.com/influxdata/influxdb.git", :tag => "v1.2.0", :revision => "b7bb7e8359642b6e071735b50ae41f5eb343fd42" head "https://github.com/influxdata/influxdb.git" bottle do sha256 "9fd2c9d0c2b2f0e6c0e89b104bc0121c551b7214144aec236b4247ba65c6d7bc" => :sierra sha256 "ac92f169a6bf7bc7cb9341293ea8167991867a54525ff75b5f6b66b0a4e1ec1d" => :el_capitan sha256 "13bbdf3b080082ee7bc07cbae5ecb798bdbe08dff7e73821fb3e8a186122f0e1" => :yosemite end depends_on "gdm" => :build depends_on "go" => :build def install ENV["GOPATH"] = buildpath influxdb_path = buildpath/"src/github.com/influxdata/influxdb" influxdb_path.install Dir["*"] revision = `git rev-parse HEAD`.strip version = `git describe --tags`.strip cd influxdb_path do system "gdm", "restore" system "go", "install", "-ldflags", "-X main.version=#{version} -X main.commit=#{revision} -X main.branch=master", "./..." end inreplace influxdb_path/"etc/config.sample.toml" do |s| s.gsub! "/var/lib/influxdb/data", "#{var}/influxdb/data" s.gsub! "/var/lib/influxdb/meta", "#{var}/influxdb/meta" s.gsub! "/var/lib/influxdb/wal", "#{var}/influxdb/wal" end bin.install "bin/influxd" bin.install "bin/influx" bin.install "bin/influx_tsm" bin.install "bin/influx_stress" etc.install influxdb_path/"etc/config.sample.toml" => "influxdb.conf" (var/"influxdb/data").mkpath (var/"influxdb/meta").mkpath (var/"influxdb/wal").mkpath end plist_options :manual => "influxd -config #{HOMEBREW_PREFIX}/etc/influxdb.conf" def plist; <<-EOS.undent KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{opt_bin}/influxd -config #{HOMEBREW_PREFIX}/etc/influxdb.conf RunAtLoad WorkingDirectory #{var} StandardErrorPath #{var}/log/influxdb.log StandardOutPath #{var}/log/influxdb.log SoftResourceLimits NumberOfFiles 10240 EOS end test do (testpath/"config.toml").write shell_output("#{bin}/influxd config") inreplace testpath/"config.toml" do |s| s.gsub! %r{/.*/.influxdb/data}, "#{testpath}/influxdb/data" s.gsub! %r{/.*/.influxdb/meta}, "#{testpath}/influxdb/meta" s.gsub! %r{/.*/.influxdb/wal}, "#{testpath}/influxdb/wal" end begin pid = fork do exec "#{bin}/influxd -config #{testpath}/config.toml" end sleep 1 output = shell_output("curl -Is localhost:8086/ping") sleep 1 assert_match /X-Influxdb-Version:/, output ensure Process.kill("SIGINT", pid) Process.wait(pid) end end end