128 lines
4.4 KiB
Ruby
128 lines
4.4 KiB
Ruby
class Elasticsearch < Formula
|
|
desc "Distributed search & analytics engine"
|
|
homepage "https://www.elastic.co/products/elasticsearch"
|
|
url "https://github.com/elastic/elasticsearch/archive/v7.8.1.tar.gz"
|
|
sha256 "e222d4165fb4145222491e1ed33dad15acc7b56334ca6589202e2ee761900c78"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "6cef7f769428a47c864edccc30b043153fa239fc5c5545b661975b7cef17efe7" => :catalina
|
|
sha256 "812838714ceb91031ae6ccc4b762a42fc2f52a8f43dbb9b74e3222a2a6c2b6cd" => :mojave
|
|
sha256 "666d9a971e6f8a603a96feac7afaaf95e6d88eabf4ecc3d6f1b1f02ff928fa3e" => :high_sierra
|
|
end
|
|
|
|
depends_on "gradle" => :build
|
|
depends_on "openjdk"
|
|
|
|
def cluster_name
|
|
"elasticsearch_#{ENV["USER"]}"
|
|
end
|
|
|
|
def install
|
|
system "gradle", ":distribution:archives:oss-no-jdk-darwin-tar:assemble"
|
|
|
|
mkdir "tar" do
|
|
# Extract the package to the tar directory
|
|
system "tar", "--strip-components=1", "-xf",
|
|
Dir["../distribution/archives/oss-no-jdk-darwin-tar/build/distributions/elasticsearch-oss-*.tar.gz"].first
|
|
|
|
# Install into package directory
|
|
libexec.install "bin", "lib", "modules"
|
|
|
|
# Set up Elasticsearch for local development:
|
|
inreplace "config/elasticsearch.yml" do |s|
|
|
# 1. Give the cluster a unique name
|
|
s.gsub!(/#\s*cluster\.name: .*/, "cluster.name: #{cluster_name}")
|
|
|
|
# 2. Configure paths
|
|
s.sub!(%r{#\s*path\.data: /path/to.+$}, "path.data: #{var}/lib/elasticsearch/")
|
|
s.sub!(%r{#\s*path\.logs: /path/to.+$}, "path.logs: #{var}/log/elasticsearch/")
|
|
end
|
|
|
|
inreplace "config/jvm.options", %r{logs/gc.log}, "#{var}/log/elasticsearch/gc.log"
|
|
|
|
# Move config files into etc
|
|
(etc/"elasticsearch").install Dir["config/*"]
|
|
end
|
|
|
|
inreplace libexec/"bin/elasticsearch-env",
|
|
"if [ -z \"$ES_PATH_CONF\" ]; then ES_PATH_CONF=\"$ES_HOME\"/config; fi",
|
|
"if [ -z \"$ES_PATH_CONF\" ]; then ES_PATH_CONF=\"#{etc}/elasticsearch\"; fi"
|
|
|
|
bin.install libexec/"bin/elasticsearch",
|
|
libexec/"bin/elasticsearch-keystore",
|
|
libexec/"bin/elasticsearch-plugin",
|
|
libexec/"bin/elasticsearch-shard"
|
|
bin.env_script_all_files(libexec/"bin", JAVA_HOME: Formula["openjdk"].opt_prefix)
|
|
end
|
|
|
|
def post_install
|
|
# Make sure runtime directories exist
|
|
(var/"lib/elasticsearch").mkpath
|
|
(var/"log/elasticsearch").mkpath
|
|
ln_s etc/"elasticsearch", libexec/"config" unless (libexec/"config").exist?
|
|
(var/"elasticsearch/plugins").mkpath
|
|
ln_s var/"elasticsearch/plugins", libexec/"plugins" unless (libexec/"plugins").exist?
|
|
# fix test not being able to create keystore because of sandbox permissions
|
|
system bin/"elasticsearch-keystore", "create" unless (etc/"elasticsearch/elasticsearch.keystore").exist?
|
|
end
|
|
|
|
def caveats
|
|
<<~EOS
|
|
Data: #{var}/lib/elasticsearch/
|
|
Logs: #{var}/log/elasticsearch/#{cluster_name}.log
|
|
Plugins: #{var}/elasticsearch/plugins/
|
|
Config: #{etc}/elasticsearch/
|
|
EOS
|
|
end
|
|
|
|
plist_options manual: "elasticsearch"
|
|
|
|
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}/elasticsearch</string>
|
|
</array>
|
|
<key>EnvironmentVariables</key>
|
|
<dict>
|
|
</dict>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>WorkingDirectory</key>
|
|
<string>#{var}</string>
|
|
<key>StandardErrorPath</key>
|
|
<string>#{var}/log/elasticsearch.log</string>
|
|
<key>StandardOutPath</key>
|
|
<string>#{var}/log/elasticsearch.log</string>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
port = free_port
|
|
(testpath/"data").mkdir
|
|
(testpath/"logs").mkdir
|
|
fork do
|
|
exec bin/"elasticsearch", "-Ehttp.port=#{port}",
|
|
"-Epath.data=#{testpath}/data",
|
|
"-Epath.logs=#{testpath}/logs"
|
|
end
|
|
sleep 20
|
|
output = shell_output("curl -s -XGET localhost:#{port}/")
|
|
assert_equal "oss", JSON.parse(output)["version"]["build_flavor"]
|
|
|
|
system "#{bin}/elasticsearch-plugin", "list"
|
|
end
|
|
end
|