homebrew-core/Formula/zookeeper.rb

131 lines
4.1 KiB
Ruby

class Zookeeper < Formula
desc "Centralized server for distributed coordination of services"
homepage "https://zookeeper.apache.org/"
url "https://www.apache.org/dyn/closer.lua?path=zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1.tar.gz"
mirror "https://archive.apache.org/dist/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1.tar.gz"
sha256 "0fc25db4ee790e04e7de42d4ce64bde63136d5ea5db01fb643bd37b52b05968d"
license "Apache-2.0"
head "https://gitbox.apache.org/repos/asf/zookeeper.git"
livecheck do
url :stable
end
bottle do
cellar :any
sha256 "4526d63e4c1d7afcba6a507c1c741e854c3d73cb7ba556941891add904d317f8" => :catalina
sha256 "a0762d53a75c01503e43cab621cf8da4a96f3baed1ef6148e17e577956db3b6c" => :mojave
sha256 "5493817b0e8dfb6c8c7fcf40491c6c10b1eb0e38292d42da981686b1ea1fb7c9" => :high_sierra
end
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "cppunit" => :build
depends_on "libtool" => :build
depends_on "maven" => :build
depends_on "pkg-config" => :build
def shim_script(target)
<<~EOS
#!/usr/bin/env bash
. "#{etc}/zookeeper/defaults"
cd "#{libexec}/bin"
./#{target} "$@"
EOS
end
def default_zk_env
<<~EOS
[ -z "$ZOOCFGDIR" ] && export ZOOCFGDIR="#{etc}/zookeeper"
EOS
end
def default_log4j_properties
<<~EOS
log4j.rootCategory=WARN, zklog
log4j.appender.zklog = org.apache.log4j.RollingFileAppender
log4j.appender.zklog.File = #{var}/log/zookeeper/zookeeper.log
log4j.appender.zklog.Append = true
log4j.appender.zklog.layout = org.apache.log4j.PatternLayout
log4j.appender.zklog.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
EOS
end
def install
system "mvn", "install", "-Pfull-build", "-DskipTests"
system "tar", "-xf", "zookeeper-assembly/target/apache-zookeeper-#{version}-bin.tar.gz"
binpfx = "apache-zookeeper-#{version}-bin"
libexec.install binpfx+"/bin", binpfx+"/lib", "zookeeper-contrib"
rm_f Dir["build-bin/bin/*.cmd"]
system "tar", "-xf", "zookeeper-assembly/target/apache-zookeeper-#{version}-lib.tar.gz"
libpfx = "apache-zookeeper-#{version}-lib"
include.install Dir[libpfx+"/usr/include/*"]
lib.install Dir[libpfx+"/usr/lib/*"]
bin.mkpath
(etc/"zookeeper").mkpath
(var/"log/zookeeper").mkpath
(var/"run/zookeeper/data").mkpath
Pathname.glob("#{libexec}/bin/*.sh") do |path|
next if path == libexec+"bin/zkEnv.sh"
script_name = path.basename
bin_name = path.basename ".sh"
(bin+bin_name).write shim_script(script_name)
end
defaults = etc/"zookeeper/defaults"
defaults.write(default_zk_env) unless defaults.exist?
log4j_properties = etc/"zookeeper/log4j.properties"
log4j_properties.write(default_log4j_properties) unless log4j_properties.exist?
inreplace "conf/zoo_sample.cfg",
/^dataDir=.*/, "dataDir=#{var}/run/zookeeper/data"
cp "conf/zoo_sample.cfg", "conf/zoo.cfg"
(etc/"zookeeper").install ["conf/zoo.cfg", "conf/zoo_sample.cfg"]
end
plist_options manual: "zkServer start"
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>EnvironmentVariables</key>
<dict>
<key>SERVER_JVMFLAGS</key>
<string>-Dapple.awt.UIElement=true</string>
</dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/zkServer</string>
<string>start-foreground</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
</dict>
</plist>
EOS
end
test do
output = shell_output("#{bin}/zkServer -h 2>&1")
assert_match "Using config: #{etc}/zookeeper/zoo.cfg", output
end
end