class Zookeeper < Formula desc "Centralized server for distributed coordination of services" homepage "https://zookeeper.apache.org/" url "https://www.apache.org/dyn/closer.cgi?path=zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz" sha256 "7ced798e41d2027784b8fd55c908605ad5bd94a742d5dab2506be8f94770594d" bottle do cellar :any sha256 "d1e4e7738cd147dceb3d91b32480c20ac5da27d129905f336ba51c0c01b8a476" => :mojave sha256 "806ec4f5c3c63387ffa3d1934764b3ebedcacdeffaa26661ae203c71be7d707b" => :high_sierra sha256 "ea14de526563c5a1d5edd84c40383c75bef5dcf135b80dbc54af14f8b70cc68f" => :sierra end head do url "https://svn.apache.org/repos/asf/zookeeper/trunk" depends_on "ant" => :build depends_on "autoconf" => :build depends_on "automake" => :build depends_on "cppunit" => :build depends_on "libtool" => :build end 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 if build.head? system "ant", "compile_jute" system "autoreconf", "-fvi", "src/c" end cd "src/c" do system "./configure", "--disable-dependency-tracking", "--prefix=#{prefix}", "--without-cppunit" system "make", "install" end rm_f Dir["bin/*.cmd"] if build.head? system "ant" libexec.install "bin", "src/contrib", "src/java/lib" libexec.install Dir["build/*.jar"] else libexec.install "bin", "contrib", "lib" libexec.install Dir["*.jar"] end 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 EnvironmentVariables SERVER_JVMFLAGS -Dapple.awt.UIElement=true KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{opt_bin}/zkServer start-foreground RunAtLoad WorkingDirectory #{var} EOS end test do output = shell_output("#{bin}/zkServer -h 2>&1") assert_match "Using config: #{etc}/zookeeper/zoo.cfg", output end end