homebrew-core/Formula/logstash.rb

107 lines
3.8 KiB
Ruby

class Logstash < Formula
desc "Tool for managing events and logs"
homepage "https://www.elastic.co/products/logstash"
url "https://github.com/elastic/logstash/archive/v8.5.3.tar.gz"
sha256 "423cf8ebb8719afb7b3c1e4f8e26d9e0726494263714ee4ac32e3ccf9533f403"
license "Apache-2.0"
version_scheme 1
head "https://github.com/elastic/logstash.git", branch: "main"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any, arm64_ventura: "9216b48898c11f1ecd966d95e0d420857be8a2ce93a0d54aba1cadd59d1ab6b4"
sha256 cellar: :any, arm64_monterey: "4acff2f7e5cb2307ee5bd50ac398a5300e10814eb451426087e6029c5821d575"
sha256 cellar: :any, arm64_big_sur: "fd4dcbbc672f8656f5b8090ecaf2ed4f02b76ed9674e8f4f98185c1ab0b43bdd"
sha256 cellar: :any, ventura: "0d8d7977cc937cd9f895567831e172fc8ca8fe37645d2f20d33ad2db1d855744"
sha256 cellar: :any, monterey: "31a0992bbd16746aed1f399ed0b695dce76bd2201dbbbcb959a6d3d1d8bbbd05"
sha256 cellar: :any, big_sur: "7cf6c984142da63413eacb518bb077b4f1ce269229f1b7dc33b30a42a8af3706"
sha256 cellar: :any_skip_relocation, x86_64_linux: "bcffa3a2dadc932556a40afa00f4508e87a60ef26b26eb65b1fdb47e2bc869d8"
end
depends_on "openjdk@17"
uses_from_macos "ruby" => :build
def install
# remove non open source files
rm_rf "x-pack"
ENV["OSS"] = "true"
# Build the package from source
system "rake", "artifact:no_bundle_jdk_tar"
# Extract the package to the current directory
mkdir "tar"
system "tar", "--strip-components=1", "-xf", Dir["build/logstash-*.tar.gz"].first, "-C", "tar"
cd "tar"
inreplace "bin/logstash",
%r{^\. "\$\(cd `dirname \$\{SOURCEPATH\}`/\.\.; pwd\)/bin/logstash\.lib\.sh"},
". #{libexec}/bin/logstash.lib.sh"
inreplace "bin/logstash-plugin",
%r{^\. "\$\(cd `dirname \$0`/\.\.; pwd\)/bin/logstash\.lib\.sh"},
". #{libexec}/bin/logstash.lib.sh"
inreplace "bin/logstash.lib.sh",
/^LOGSTASH_HOME=.*$/,
"LOGSTASH_HOME=#{libexec}"
# Delete Windows and other Arch/OS files
paths_to_keep = OS.linux? ? "#{Hardware::CPU.arch}-#{OS.kernel_name}" : OS.kernel_name
rm Dir["bin/*.bat"]
Dir["vendor/jruby/lib/jni/*"].each do |path|
rm_r path unless path.include? paths_to_keep
end
libexec.install Dir["*"]
# Move config files into etc
(etc/"logstash").install Dir[libexec/"config/*"]
(libexec/"config").rmtree
bin.install libexec/"bin/logstash", libexec/"bin/logstash-plugin"
bin.env_script_all_files libexec/"bin", LS_JAVA_HOME: "${LS_JAVA_HOME:-#{Language::Java.java_home("17")}}"
end
def post_install
ln_s etc/"logstash", libexec/"config"
end
def caveats
<<~EOS
Configuration files are located in #{etc}/logstash/
EOS
end
service do
run opt_bin/"logstash"
keep_alive false
working_dir var
log_path var/"log/logstash.log"
error_log_path var/"log/logstash.log"
end
test do
# workaround https://github.com/elastic/logstash/issues/6378
(testpath/"config").mkpath
["jvm.options", "log4j2.properties", "startup.options"].each do |f|
cp prefix/"libexec/config/#{f}", testpath/"config"
end
(testpath/"config/logstash.yml").write <<~EOS
path.queue: #{testpath}/queue
EOS
(testpath/"data").mkpath
(testpath/"logs").mkpath
(testpath/"queue").mkpath
data = "--path.data=#{testpath}/data"
logs = "--path.logs=#{testpath}/logs"
settings = "--path.settings=#{testpath}/config"
output = pipe_output("#{bin}/logstash -e '' #{data} #{logs} #{settings} --log.level=fatal", "hello world\n")
assert_match "hello world", output
end
end