homebrew-core/Formula/logstash.rb
Christian Moritz e42cd8e28f
logstash 6.7.0
Closes #38413.

Signed-off-by: Chongyu Zhu <i@lembacon.com>
2019-03-28 03:10:32 +08:00

104 lines
3.2 KiB
Ruby

class Logstash < Formula
desc "Tool for managing events and logs"
homepage "https://www.elastic.co/products/logstash"
url "https://artifacts.elastic.co/downloads/logstash/logstash-oss-6.7.0.tar.gz"
sha256 "8dc6a068fbf92541d1d57b816728855f0d9116c1142f79cf2691f755fc45b0c4"
head "https://github.com/elastic/logstash.git"
bottle :unneeded
depends_on :java => "1.8"
def install
if build.head?
# Build the package from source
system "rake", "artifact: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"
end
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}"
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", Language::Java.java_home_env("1.8"))
end
def post_install
ln_s etc/"logstash", libexec/"config"
end
def caveats; <<~EOS
Configuration files are located in #{etc}/logstash/
EOS
end
plist_options :manual => "logstash"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/logstash</string>
</array>
<key>EnvironmentVariables</key>
<dict>
</dict>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/logstash.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/logstash.log</string>
</dict>
</plist>
EOS
end
test do
assert_includes(stable.url, "-oss-")
# 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