class Cassandra < Formula desc "Eventually consistent, distributed key-value store" homepage "https://cassandra.apache.org" url "https://www.apache.org/dyn/closer.cgi?path=cassandra/3.11.2/apache-cassandra-3.11.2-bin.tar.gz" sha256 "e922770ad95d5288d42442c3cfa1475938597b38418b7be5c4234a9de388c720" revision 1 bottle do cellar :any_skip_relocation sha256 "9609704a7870ee077dc3edf67da2488a0877f0124542b5a7e80dc7a52d3704e7" => :high_sierra sha256 "3f62e647a3dd80bfcff060e5122df5b6a60440e7fca02ad51b416620698361cf" => :sierra sha256 "ff780a2b88ae8a3a619aa0a9429570a94ef6fe40c008392e5b046a7e3799dc2a" => :el_capitan end depends_on "python@2" depends_on "cython" # Only >=Yosemite has new enough setuptools for successful compile of the below deps. resource "setuptools" do url "https://files.pythonhosted.org/packages/e0/02/2b14188e06ddf61e5b462e216b15d893e8472fca28b1b0c5d9272ad7e87c/setuptools-38.5.2.zip" sha256 "8246123e984cadf687163bdcd1bb58eb325e2891b066e1f0224728a41c8d9064" end resource "futures" do url "https://files.pythonhosted.org/packages/1f/9e/7b2ff7e965fc654592269f2906ade1c7d705f1bf25b7d469fa153f7d19eb/futures-3.2.0.tar.gz" sha256 "9ec02aa7d674acb8618afb127e27fde7fc68994c0437ad759fa094a574adb265" end resource "six" do url "https://files.pythonhosted.org/packages/16/d8/bc6316cf98419719bd59c91742194c111b6f2e85abac88e496adefaf7afe/six-1.11.0.tar.gz" sha256 "70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9" end resource "thrift" do url "https://files.pythonhosted.org/packages/c6/b4/510617906f8e0c5660e7d96fbc5585113f83ad547a3989b80297ac72a74c/thrift-0.11.0.tar.gz" sha256 "7d59ac4fdcb2c58037ebd4a9da5f9a49e3e034bf75b3f26d9fe48ba3d8806e6b" end resource "cql" do url "https://files.pythonhosted.org/packages/0b/15/523f6008d32f05dd3c6a2e7c2f21505f0a785b6dc8949cad325306858afc/cql-1.4.0.tar.gz" sha256 "7857c16d8aab7b736ab677d1016ef8513dedb64097214ad3a50a6c550cb7d6e0" end resource "cassandra-driver" do url "https://files.pythonhosted.org/packages/2d/77/2e344b58ffe8b11271735c1ee88fa668c897c5b72ed1913067dd86e1a966/cassandra-driver-3.13.0.tar.gz" sha256 "61b670fb2ba95d51d91fa7b589aae3666df494713f5d1ed78bb5c510778d77f0" end def install (var/"lib/cassandra").mkpath (var/"log/cassandra").mkpath pypath = libexec/"vendor/lib/python2.7/site-packages" ENV.prepend_create_path "PYTHONPATH", pypath resources.each do |r| r.stage do system "python", *Language::Python.setup_install_args(libexec/"vendor") end end inreplace "conf/cassandra.yaml", "/var/lib/cassandra", "#{var}/lib/cassandra" inreplace "conf/cassandra-env.sh", "/lib/", "/" inreplace "bin/cassandra", "-Dcassandra.logdir\=$CASSANDRA_HOME/logs", "-Dcassandra.logdir\=#{var}/log/cassandra" inreplace "bin/cassandra.in.sh" do |s| s.gsub! "CASSANDRA_HOME=\"`dirname \"$0\"`/..\"", "CASSANDRA_HOME=\"#{libexec}\"" # Store configs in etc, outside of keg s.gsub! "CASSANDRA_CONF=\"$CASSANDRA_HOME/conf\"", "CASSANDRA_CONF=\"#{etc}/cassandra\"" # Jars installed to prefix, no longer in a lib folder s.gsub! "\"$CASSANDRA_HOME\"/lib/*.jar", "\"$CASSANDRA_HOME\"/*.jar" # The jammm Java agent is not in a lib/ subdir either: s.gsub! "JAVA_AGENT=\"$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-", "JAVA_AGENT=\"$JAVA_AGENT -javaagent:$CASSANDRA_HOME/jamm-" # Storage path s.gsub! "cassandra_storagedir\=\"$CASSANDRA_HOME/data\"", "cassandra_storagedir\=\"#{var}/lib/cassandra\"" end rm Dir["bin/*.bat", "bin/*.ps1"] # This breaks on `brew uninstall cassandra && brew install cassandra` # https://github.com/Homebrew/homebrew/pull/38309 (etc/"cassandra").install Dir["conf/*"] libexec.install Dir["*.txt", "{bin,interface,javadoc,pylib,lib/licenses}"] libexec.install Dir["lib/*.jar"] pkgshare.install [libexec/"bin/cassandra.in.sh", libexec/"bin/stop-server"] inreplace Dir["#{libexec}/bin/cassandra*", "#{libexec}/bin/debug-cql", "#{libexec}/bin/nodetool", "#{libexec}/bin/sstable*"], %r{`dirname "?\$0"?`/cassandra.in.sh}, "#{pkgshare}/cassandra.in.sh" # Make sure tools are installed rm Dir[buildpath/"tools/bin/*.bat"] # Delete before install to avoid copying useless files (libexec/"tools").install Dir[buildpath/"tools/lib/*.jar"] # Tools use different cassandra.in.sh and should be changed differently mv buildpath/"tools/bin/cassandra.in.sh", buildpath/"tools/bin/cassandra-tools.in.sh" inreplace buildpath/"tools/bin/cassandra-tools.in.sh" do |s| # Tools have slightly different path to CASSANDRA_HOME s.gsub! "CASSANDRA_HOME=\"`dirname $0`/../..\"", "CASSANDRA_HOME=\"#{libexec}\"" # Store configs in etc, outside of keg s.gsub! "CASSANDRA_CONF=\"$CASSANDRA_HOME/conf\"", "CASSANDRA_CONF=\"#{etc}/cassandra\"" # Core Jars installed to prefix, no longer in a lib folder s.gsub! "\"$CASSANDRA_HOME\"/lib/*.jar", "\"$CASSANDRA_HOME\"/*.jar" # Tools Jars are under tools folder s.gsub! "\"$CASSANDRA_HOME\"/tools/lib/*.jar", "\"$CASSANDRA_HOME\"/tools/*.jar" # Storage path s.gsub! "cassandra_storagedir\=\"$CASSANDRA_HOME/data\"", "cassandra_storagedir\=\"#{var}/lib/cassandra\"" end pkgshare.install [buildpath/"tools/bin/cassandra-tools.in.sh"] # Update tools script files inreplace Dir[buildpath/"tools/bin/*"], "`dirname \"$0\"`/cassandra.in.sh", "#{pkgshare}/cassandra-tools.in.sh" # Make sure tools are available bin.install Dir[buildpath/"tools/bin/*"] bin.write_exec_script Dir["#{libexec}/bin/*"] rm %W[#{bin}/cqlsh #{bin}/cqlsh.py] # Remove existing exec scripts (bin/"cqlsh").write_env_script libexec/"bin/cqlsh", :PYTHONPATH => pypath (bin/"cqlsh.py").write_env_script libexec/"bin/cqlsh.py", :PYTHONPATH => pypath end plist_options :manual => "cassandra -f" def plist; <<~EOS KeepAlive Label #{plist_name} ProgramArguments #{opt_bin}/cassandra -f RunAtLoad WorkingDirectory #{var}/lib/cassandra EOS end test do assert_match version.to_s, shell_output("#{bin}/cassandra -v") output = shell_output("#{bin}/cqlsh localhost 2>&1", 1) assert_match "Connection error", output end end