-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
cassandra.rb
151 lines (124 loc) · 6.65 KB
/
cassandra.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
class Cassandra < Formula
include Language::Python::Virtualenv
include Language::Python::Shebang
desc "Eventually consistent, distributed key-value store"
homepage "https://cassandra.apache.org"
url "https://www.apache.org/dyn/closer.lua?path=cassandra/5.0.2/apache-cassandra-5.0.2-bin.tar.gz"
mirror "https://archive.apache.org/dist/cassandra/5.0.2/apache-cassandra-5.0.2-bin.tar.gz"
sha256 "d721834207838b9d01919dfc33625ad17b50fea03bf9f76cdd8d3ae3a8fd2947"
license "Apache-2.0"
bottle do
sha256 cellar: :any, arm64_sequoia: "d93811c988659dac067376da548017ae75ed5386588c0ab46f616dc3de91b06c"
sha256 cellar: :any, arm64_sonoma: "8aacacac5194c0b57467acc457c7267457f11b323fad6e8e1501cfe85caa2d93"
sha256 cellar: :any, arm64_ventura: "ae588dbb3d91beddea60d6c22635f8bc42a443425cefabb35f899e85f24c50dd"
sha256 cellar: :any, sonoma: "5ae4378828dcbf84131cef2132a2ea91b9c4ccb75d7e0ba42abd14bd802f24b8"
sha256 cellar: :any, ventura: "7a35926ce1e8f6bda081ff85fd32421eadd643b67dcc6a7b4fa3d3df2ee1ec22"
sha256 cellar: :any_skip_relocation, x86_64_linux: "4c79b9928798c75d5a32d1dd71c62cb7343a7c89713a5d500325302206403b9c"
end
depends_on "libev"
depends_on "openjdk@17"
depends_on "python@3.11" # required 3.8-3.11, https://github.com/apache/cassandra/blob/trunk/bin/cqlsh#L65-L73
conflicts_with "emqx", because: "both install `nodetool` binaries"
resource "cassandra-driver" do
url "https://files.pythonhosted.org/packages/b2/6f/d25121afaa2ea0741d05d2e9921a7ca9b4ce71634b16a8aaee21bd7af818/cassandra-driver-3.29.2.tar.gz"
sha256 "c4310a7d0457f51a63fb019d8ef501588c491141362b53097fbc62fa06559b7c"
end
resource "click" do
url "https://files.pythonhosted.org/packages/96/d3/f04c7bfcf5c1862a2a5b845c6b2b360488cf47af55dfa79c98f6a6bf98b5/click-8.1.7.tar.gz"
sha256 "ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"
end
resource "geomet" do
url "https://files.pythonhosted.org/packages/cf/21/58251b3de99e0b5ba649ff511f7f9e8399c3059dd52a643774106e929afa/geomet-0.2.1.post1.tar.gz"
sha256 "91d754f7c298cbfcabd3befdb69c641c27fe75e808b27aa55028605761d17e95"
end
resource "six" do
url "https://files.pythonhosted.org/packages/71/39/171f1c67cd00715f190ba0b100d606d440a28c93c7714febeca8b79af85e/six-1.16.0.tar.gz"
sha256 "1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"
end
resource "wcwidth" do
url "https://files.pythonhosted.org/packages/6c/63/53559446a878410fc5a5974feb13d31d78d752eb18aeba59c7fef1af7598/wcwidth-0.2.13.tar.gz"
sha256 "72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"
end
def install
(var/"lib/cassandra").mkpath
(var/"log/cassandra").mkpath
python3 = "python3.11"
venv = virtualenv_create(libexec/"vendor", python3)
venv.pip_install resources
inreplace "conf/cassandra.yaml", "/var/lib/cassandra", var/"lib/cassandra"
inreplace "conf/cassandra-env.sh", "/lib/", "/"
inreplace "bin/cassandra", "-Dcassandra.logdir=$CASSANDRA_LOG_DIR",
"-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\""
s.gsub! "#JAVA_HOME=/usr/local/jdk6",
"JAVA_HOME=#{Language::Java.overridable_java_home_env("17")[:JAVA_HOME]}"
end
rm Dir["bin/*.bat", "bin/*.ps1"]
# This breaks on `brew uninstall cassandra && brew install cassandra`
# https://github.com/Homebrew/homebrew/pull/38309
pkgetc.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"
venv_bin = libexec/"vendor/bin"
rw_info = python_shebang_rewrite_info(venv_bin/python3)
rewrite_shebang rw_info, libexec/"bin/cqlsh.py"
# Make sure tools are available
bin.install Dir[buildpath/"tools/bin/*"]
bin.write_exec_script Dir[libexec/"bin/*"]
(bin/"cqlsh").write_env_script libexec/"bin/cqlsh", PATH: "#{venv_bin}:$PATH"
end
service do
run [opt_bin/"cassandra", "-f"]
keep_alive true
working_dir var/"lib/cassandra"
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