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.10/zookeeper-3.4.10.tar.gz" mirror "http://mirror.nbtelecom.com.br/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz" sha256 "7f7f5414e044ac11fee2a1e0bc225469f51fb0cdf821e67df762a43098223f27" bottle do cellar :any sha256 "a28854138a8529d7b971550566576e9758bc27a65b1d5649a574f3181b49aeee" => :sierra sha256 "a3231fd05efa548a5171e6ab2328cbb503646b952bce3b8cf1c1ce4a007f833f" => :el_capitan sha256 "2004ccbabfd5645e95af658684c0a919c13a41b45127be77db289453facf1670" => :yosemite end head do url "https://svn.apache.org/repos/asf/zookeeper/trunk" depends_on "ant" => :build depends_on "cppunit" => :build depends_on "libtool" => :build depends_on "autoconf" => :build depends_on "automake" => :build end option "with-perl", "Build Perl bindings" deprecated_option "perl" => "with-perl" depends_on :python => :optional def shim_script(target) <<-EOS.undent #!/usr/bin/env bash . "#{etc}/zookeeper/defaults" cd "#{libexec}/bin" ./#{target} "$@" EOS end def default_zk_env <<-EOS.undent [ -z "$ZOOCFGDIR" ] && export ZOOCFGDIR="#{etc}/zookeeper" EOS end def default_log4j_properties <<-EOS.undent log4j.rootCategory=WARN, zklog log4j.appender.zklog = org.apache.log4j.FileAppender 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 # Don't try to build extensions for PPC if Hardware::CPU.is_32_bit? ENV["ARCHFLAGS"] = "-arch #{Hardware::CPU.arch_32_bit}" else ENV["ARCHFLAGS"] = Hardware::CPU.universal_archs.as_arch_flags end 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 if build.with? "python" cd "src/contrib/zkpython" do system "python", "src/python/setup.py", "build" system "python", "src/python/setup.py", "install", "--prefix=#{prefix}" end end if build.with? "perl" cd "src/contrib/zkperl" do system "perl", "Makefile.PL", "PREFIX=#{prefix}", "--zookeeper-include=#{include}", "--zookeeper-lib=#{lib}" system "make", "install" end end rm_f Dir["bin/*.cmd"] if build.head? system "ant" libexec.install Dir["bin", "src/contrib", "src/java/lib", "build/*.jar"] else libexec.install Dir["bin", "contrib", "lib", "*.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.undent 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