102 lines
3.8 KiB
Ruby
102 lines
3.8 KiB
Ruby
class Opensearch < Formula
|
|
desc "Open source distributed and RESTful search engine"
|
|
homepage "https://github.com/opensearch-project/OpenSearch"
|
|
url "https://github.com/opensearch-project/OpenSearch/archive/refs/tags/1.0.0-beta1.tar.gz"
|
|
sha256 "d23385aa42f636049ae270bdb496843dc8d2dfd88bd7f4761e305e8193b76399"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, big_sur: "3e76febc9b36676a9eb2ca55cc31ff4723783d74f47924c76d83701fb299c25d"
|
|
sha256 cellar: :any_skip_relocation, catalina: "a1fe07b1db26074848cca54545c795156dfd26c49493a52605f3809206f7d988"
|
|
sha256 cellar: :any_skip_relocation, mojave: "9aac76b813d07a95636df64b4c8b96c6aa5de5a464f728a53568a51d457d92a1"
|
|
end
|
|
|
|
depends_on "gradle@6" => :build
|
|
depends_on "openjdk"
|
|
|
|
def install
|
|
system "gradle", ":distribution:archives:no-jdk-darwin-tar:assemble"
|
|
|
|
mkdir "tar" do
|
|
# Extract the package to the tar directory
|
|
system "tar", "--strip-components=1", "-xf",
|
|
Dir["../distribution/archives/no-jdk-darwin-tar/build/distributions/opensearch-*.tar.gz"].first
|
|
|
|
# Install into package directory
|
|
libexec.install "bin", "lib", "modules"
|
|
|
|
# Set up Opensearch for local development:
|
|
inreplace "config/opensearch.yml" do |s|
|
|
# 1. Give the cluster a unique name
|
|
s.gsub!(/#\s*cluster\.name: .*/, "cluster.name: opensearch_homebrew")
|
|
|
|
# 2. Configure paths
|
|
s.sub!(%r{#\s*path\.data: /path/to.+$}, "path.data: #{var}/lib/opensearch/")
|
|
s.sub!(%r{#\s*path\.logs: /path/to.+$}, "path.logs: #{var}/log/opensearch/")
|
|
end
|
|
|
|
inreplace "config/jvm.options", %r{logs/gc.log}, "#{var}/log/opensearch/gc.log"
|
|
|
|
# add placeholder to avoid removal of empty directory
|
|
touch "config/jvm.options.d/.keepme"
|
|
|
|
# Move config files into etc
|
|
(etc/"opensearch").install Dir["config/*"]
|
|
end
|
|
|
|
inreplace libexec/"bin/opensearch-env",
|
|
"if [ -z \"$OPENSEARCH_PATH_CONF\" ]; then OPENSEARCH_PATH_CONF=\"$OPENSEARCH_HOME\"/config; fi",
|
|
"if [ -z \"$OPENSEARCH_PATH_CONF\" ]; then OPENSEARCH_PATH_CONF=\"#{etc}/opensearch\"; fi"
|
|
|
|
bin.install libexec/"bin/opensearch",
|
|
libexec/"bin/opensearch-keystore",
|
|
libexec/"bin/opensearch-plugin",
|
|
libexec/"bin/opensearch-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/opensearch").mkpath
|
|
(var/"log/opensearch").mkpath
|
|
ln_s etc/"opensearch", libexec/"config" unless (libexec/"config").exist?
|
|
(var/"opensearch/plugins").mkpath
|
|
ln_s var/"opensearch/plugins", libexec/"plugins" unless (libexec/"plugins").exist?
|
|
# fix test not being able to create keystore because of sandbox permissions
|
|
system bin/"opensearch-keystore", "create" unless (etc/"opensearch/opensearch.keystore").exist?
|
|
end
|
|
|
|
def caveats
|
|
<<~EOS
|
|
Data: #{var}/lib/opensearch/
|
|
Logs: #{var}/log/opensearch/opensearch_homebrew.log
|
|
Plugins: #{var}/opensearch/plugins/
|
|
Config: #{etc}/opensearch/
|
|
EOS
|
|
end
|
|
|
|
plist_options manual: "opensearch"
|
|
service do
|
|
run opt_bin/"opensearch"
|
|
working_dir var
|
|
log_path var/"log/opensearch.log"
|
|
error_log_path var/"log/opensearch.log"
|
|
end
|
|
|
|
test do
|
|
port = free_port
|
|
(testpath/"data").mkdir
|
|
(testpath/"logs").mkdir
|
|
fork do
|
|
exec bin/"opensearch", "-Ehttp.port=#{port}",
|
|
"-Epath.data=#{testpath}/data",
|
|
"-Epath.logs=#{testpath}/logs"
|
|
end
|
|
sleep 20
|
|
output = shell_output("curl -s -XGET localhost:#{port}/")
|
|
assert_equal "opensearch", JSON.parse(output)["version"]["distribution"]
|
|
|
|
system "#{bin}/opensearch-plugin", "list"
|
|
end
|
|
end
|