2016-07-22 18:29:35 +01:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.cassandra;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
defaultUser = "cassandra";
|
|
|
|
|
cassandraConfig = flip recursiveUpdate cfg.extraConfig
|
|
|
|
|
({ commitlog_sync = "batch";
|
|
|
|
|
commitlog_sync_batch_window_in_ms = 2;
|
2019-04-07 04:02:32 +01:00
|
|
|
|
start_native_transport = cfg.allowClients;
|
2019-04-07 06:22:41 +01:00
|
|
|
|
cluster_name = cfg.clusterName;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
partitioner = "org.apache.cassandra.dht.Murmur3Partitioner";
|
|
|
|
|
endpoint_snitch = "SimpleSnitch";
|
|
|
|
|
data_file_directories = [ "${cfg.homeDir}/data" ];
|
|
|
|
|
commitlog_directory = "${cfg.homeDir}/commitlog";
|
|
|
|
|
saved_caches_directory = "${cfg.homeDir}/saved_caches";
|
2019-05-02 07:59:39 +01:00
|
|
|
|
} // (lib.optionalAttrs (cfg.seedAddresses != []) {
|
|
|
|
|
seed_provider = [{
|
|
|
|
|
class_name = "org.apache.cassandra.locator.SimpleSeedProvider";
|
|
|
|
|
parameters = [ { seeds = concatStringsSep "," cfg.seedAddresses; } ];
|
|
|
|
|
}];
|
|
|
|
|
}) // (lib.optionalAttrs (lib.versionAtLeast cfg.package.version "3") {
|
|
|
|
|
hints_directory = "${cfg.homeDir}/hints";
|
|
|
|
|
})
|
2017-11-07 13:11:56 +00:00
|
|
|
|
);
|
|
|
|
|
cassandraConfigWithAddresses = cassandraConfig //
|
2019-04-24 04:48:22 +01:00
|
|
|
|
( if cfg.listenAddress == null
|
2017-11-07 13:11:56 +00:00
|
|
|
|
then { listen_interface = cfg.listenInterface; }
|
|
|
|
|
else { listen_address = cfg.listenAddress; }
|
|
|
|
|
) // (
|
2019-04-24 04:48:22 +01:00
|
|
|
|
if cfg.rpcAddress == null
|
2017-11-07 13:11:56 +00:00
|
|
|
|
then { rpc_interface = cfg.rpcInterface; }
|
|
|
|
|
else { rpc_address = cfg.rpcAddress; }
|
|
|
|
|
);
|
|
|
|
|
cassandraEtc = pkgs.stdenv.mkDerivation
|
|
|
|
|
{ name = "cassandra-etc";
|
|
|
|
|
cassandraYaml = builtins.toJSON cassandraConfigWithAddresses;
|
|
|
|
|
cassandraEnvPkg = "${cfg.package}/conf/cassandra-env.sh";
|
2018-12-05 13:56:23 +00:00
|
|
|
|
cassandraLogbackConfig = pkgs.writeText "logback.xml" cfg.logbackConfig;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
buildCommand = ''
|
|
|
|
|
mkdir -p "$out"
|
2016-07-22 18:29:35 +01:00
|
|
|
|
|
2017-11-07 13:11:56 +00:00
|
|
|
|
echo "$cassandraYaml" > "$out/cassandra.yaml"
|
2018-12-05 13:56:23 +00:00
|
|
|
|
ln -s "$cassandraLogbackConfig" "$out/logback.xml"
|
2019-04-07 05:30:26 +01:00
|
|
|
|
|
|
|
|
|
cp "$cassandraEnvPkg" "$out/cassandra-env.sh"
|
2019-04-23 03:52:44 +01:00
|
|
|
|
|
2019-04-07 05:30:26 +01:00
|
|
|
|
# Delete default JMX Port, otherwise we can't set it using env variable
|
|
|
|
|
sed -i '/JMX_PORT="7199"/d' "$out/cassandra-env.sh"
|
2019-04-23 03:52:44 +01:00
|
|
|
|
|
|
|
|
|
# Delete default password file
|
|
|
|
|
sed -i '/-Dcom.sun.management.jmxremote.password.file=\/etc\/cassandra\/jmxremote.password/d' "$out/cassandra-env.sh"
|
2017-11-07 13:11:56 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2019-04-25 23:59:23 +01:00
|
|
|
|
defaultJmxRolesFile = builtins.foldl'
|
2019-04-23 03:52:44 +01:00
|
|
|
|
(left: right: left + right) ""
|
|
|
|
|
(map (role: "${role.username} ${role.password}") cfg.jmxRoles);
|
|
|
|
|
fullJvmOptions = cfg.jvmOpts
|
|
|
|
|
++ lib.optionals (cfg.jmxRoles != []) [
|
|
|
|
|
"-Dcom.sun.management.jmxremote.authenticate=true"
|
2019-04-25 23:59:23 +01:00
|
|
|
|
"-Dcom.sun.management.jmxremote.password.file=${cfg.jmxRolesFile}"
|
2019-04-23 03:52:44 +01:00
|
|
|
|
]
|
|
|
|
|
++ lib.optionals cfg.remoteJmx [
|
|
|
|
|
"-Djava.rmi.server.hostname=${cfg.rpcAddress}"
|
|
|
|
|
];
|
2016-07-22 18:29:35 +01:00
|
|
|
|
in {
|
|
|
|
|
options.services.cassandra = {
|
2017-11-07 13:11:56 +00:00
|
|
|
|
enable = mkEnableOption ''
|
|
|
|
|
Apache Cassandra – Scalable and highly available database.
|
|
|
|
|
'';
|
2019-04-07 06:22:41 +01:00
|
|
|
|
clusterName = mkOption {
|
|
|
|
|
type = types.str;
|
2019-06-18 00:12:06 +01:00
|
|
|
|
default = "Test Cluster";
|
2019-04-07 06:22:41 +01:00
|
|
|
|
description = ''
|
|
|
|
|
The name of the cluster.
|
|
|
|
|
This setting prevents nodes in one logical cluster from joining
|
|
|
|
|
another. All nodes in a cluster must have the same value.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2016-07-22 18:29:35 +01:00
|
|
|
|
user = mkOption {
|
2017-11-07 13:11:56 +00:00
|
|
|
|
type = types.str;
|
|
|
|
|
default = defaultUser;
|
|
|
|
|
description = "Run Apache Cassandra under this user.";
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
|
|
|
|
group = mkOption {
|
|
|
|
|
type = types.str;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
default = defaultUser;
|
|
|
|
|
description = "Run Apache Cassandra under this group.";
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
homeDir = mkOption {
|
2016-07-22 18:29:35 +01:00
|
|
|
|
type = types.path;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
default = "/var/lib/cassandra";
|
|
|
|
|
description = ''
|
|
|
|
|
Home directory for Apache Cassandra.
|
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
package = mkOption {
|
|
|
|
|
type = types.package;
|
|
|
|
|
default = pkgs.cassandra;
|
|
|
|
|
defaultText = "pkgs.cassandra";
|
|
|
|
|
example = literalExample "pkgs.cassandra_3_11";
|
|
|
|
|
description = ''
|
|
|
|
|
The Apache Cassandra package to use.
|
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
jvmOpts = mkOption {
|
2016-07-22 18:29:35 +01:00
|
|
|
|
type = types.listOf types.str;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
|
|
|
|
Populate the JVM_OPT environment variable.
|
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
|
|
|
|
listenAddress = mkOption {
|
2017-11-07 13:11:56 +00:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = "127.0.0.1";
|
|
|
|
|
example = literalExample "null";
|
2016-07-22 18:29:35 +01:00
|
|
|
|
description = ''
|
2017-11-07 13:11:56 +00:00
|
|
|
|
Address or interface to bind to and tell other Cassandra nodes
|
|
|
|
|
to connect to. You _must_ change this if you want multiple
|
|
|
|
|
nodes to be able to communicate!
|
|
|
|
|
|
|
|
|
|
Set listenAddress OR listenInterface, not both.
|
|
|
|
|
|
|
|
|
|
Leaving it blank leaves it up to
|
|
|
|
|
InetAddress.getLocalHost(). This will always do the Right
|
|
|
|
|
Thing _if_ the node is properly configured (hostname, name
|
|
|
|
|
resolution, etc), and the Right Thing is to use the address
|
|
|
|
|
associated with the hostname (it might not be).
|
|
|
|
|
|
|
|
|
|
Setting listen_address to 0.0.0.0 is always wrong.
|
2016-07-22 18:29:35 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
listenInterface = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "eth1";
|
|
|
|
|
description = ''
|
|
|
|
|
Set listenAddress OR listenInterface, not both. Interfaces
|
|
|
|
|
must correspond to a single address, IP aliasing is not
|
|
|
|
|
supported.
|
2016-07-22 18:29:35 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
rpcAddress = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = "127.0.0.1";
|
|
|
|
|
example = literalExample "null";
|
2016-07-22 18:29:35 +01:00
|
|
|
|
description = ''
|
2017-11-07 13:11:56 +00:00
|
|
|
|
The address or interface to bind the native transport server to.
|
|
|
|
|
|
|
|
|
|
Set rpcAddress OR rpcInterface, not both.
|
|
|
|
|
|
|
|
|
|
Leaving rpcAddress blank has the same effect as on
|
|
|
|
|
listenAddress (i.e. it will be based on the configured hostname
|
|
|
|
|
of the node).
|
|
|
|
|
|
|
|
|
|
Note that unlike listenAddress, you can specify 0.0.0.0, but you
|
|
|
|
|
must also set extraConfig.broadcast_rpc_address to a value other
|
|
|
|
|
than 0.0.0.0.
|
|
|
|
|
|
|
|
|
|
For security reasons, you should not expose this port to the
|
|
|
|
|
internet. Firewall it if needed.
|
2016-07-22 18:29:35 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
rpcInterface = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
2016-07-22 18:29:35 +01:00
|
|
|
|
default = null;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
example = "eth1";
|
2016-07-22 18:29:35 +01:00
|
|
|
|
description = ''
|
2017-11-07 13:11:56 +00:00
|
|
|
|
Set rpcAddress OR rpcInterface, not both. Interfaces must
|
|
|
|
|
correspond to a single address, IP aliasing is not supported.
|
2016-07-22 18:29:35 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2018-12-05 13:56:23 +00:00
|
|
|
|
logbackConfig = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = ''
|
|
|
|
|
<configuration scan="false">
|
|
|
|
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
|
|
|
|
<encoder>
|
|
|
|
|
<pattern>%-5level %date{HH:mm:ss,SSS} %msg%n</pattern>
|
|
|
|
|
</encoder>
|
|
|
|
|
</appender>
|
2016-07-22 18:29:35 +01:00
|
|
|
|
|
2018-12-05 13:56:23 +00:00
|
|
|
|
<root level="INFO">
|
|
|
|
|
<appender-ref ref="STDOUT" />
|
|
|
|
|
</root>
|
|
|
|
|
|
|
|
|
|
<logger name="com.thinkaurelius.thrift" level="ERROR"/>
|
|
|
|
|
</configuration>
|
|
|
|
|
'';
|
|
|
|
|
description = ''
|
|
|
|
|
XML logback configuration for cassandra
|
|
|
|
|
'';
|
|
|
|
|
};
|
2019-04-07 04:02:51 +01:00
|
|
|
|
seedAddresses = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [ "127.0.0.1" ];
|
|
|
|
|
description = ''
|
|
|
|
|
The addresses of hosts designated as contact points in the cluster. A
|
|
|
|
|
joining node contacts one of the nodes in the seeds list to learn the
|
|
|
|
|
topology of the ring.
|
|
|
|
|
Set to 127.0.0.1 for a single node cluster.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2019-04-07 04:02:32 +01:00
|
|
|
|
allowClients = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Enables or disables the native transport server (CQL binary protocol).
|
|
|
|
|
This server uses the same address as the <literal>rpcAddress</literal>,
|
|
|
|
|
but the port it uses is not <literal>rpc_port</literal> but
|
|
|
|
|
<literal>native_transport_port</literal>. See the official Cassandra
|
|
|
|
|
docs for more information on these variables and set them using
|
|
|
|
|
<literal>extraConfig</literal>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
extraConfig = mkOption {
|
|
|
|
|
type = types.attrs;
|
|
|
|
|
default = {};
|
|
|
|
|
example =
|
|
|
|
|
{ commitlog_sync_batch_window_in_ms = 3;
|
|
|
|
|
};
|
|
|
|
|
description = ''
|
|
|
|
|
Extra options to be merged into cassandra.yaml as nix attribute set.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
fullRepairInterval = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = "3w";
|
|
|
|
|
example = literalExample "null";
|
|
|
|
|
description = ''
|
|
|
|
|
Set the interval how often full repairs are run, i.e.
|
2019-04-26 00:13:09 +01:00
|
|
|
|
<literal>nodetool repair --full</literal> is executed. See
|
2017-11-07 13:11:56 +00:00
|
|
|
|
https://cassandra.apache.org/doc/latest/operating/repair.html
|
|
|
|
|
for more information.
|
2016-07-22 18:29:35 +01:00
|
|
|
|
|
2019-04-26 00:13:09 +01:00
|
|
|
|
Set to <literal>null</literal> to disable full repairs.
|
2017-11-07 13:11:56 +00:00
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
fullRepairOptions = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [];
|
|
|
|
|
example = [ "--partitioner-range" ];
|
|
|
|
|
description = ''
|
|
|
|
|
Options passed through to the full repair command.
|
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
incrementalRepairInterval = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = "3d";
|
|
|
|
|
example = literalExample "null";
|
|
|
|
|
description = ''
|
|
|
|
|
Set the interval how often incremental repairs are run, i.e.
|
2019-06-14 04:36:06 +01:00
|
|
|
|
<literal>nodetool repair</literal> is executed. See
|
2017-11-07 13:11:56 +00:00
|
|
|
|
https://cassandra.apache.org/doc/latest/operating/repair.html
|
|
|
|
|
for more information.
|
|
|
|
|
|
2019-04-26 00:13:09 +01:00
|
|
|
|
Set to <literal>null</literal> to disable incremental repairs.
|
2017-11-07 13:11:56 +00:00
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
incrementalRepairOptions = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
|
type = types.listOf types.str;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
default = [];
|
|
|
|
|
example = [ "--partitioner-range" ];
|
|
|
|
|
description = ''
|
|
|
|
|
Options passed through to the incremental repair command.
|
|
|
|
|
'';
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
2019-04-07 05:30:26 +01:00
|
|
|
|
maxHeapSize = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
|
type = types.nullOr types.str;
|
2019-04-07 05:30:26 +01:00
|
|
|
|
default = null;
|
|
|
|
|
example = "4G";
|
|
|
|
|
description = ''
|
|
|
|
|
Must be left blank or set together with heapNewSize.
|
|
|
|
|
If left blank a sensible value for the available amount of RAM and CPU
|
|
|
|
|
cores is calculated.
|
|
|
|
|
|
|
|
|
|
Override to set the amount of memory to allocate to the JVM at
|
|
|
|
|
start-up. For production use you may wish to adjust this for your
|
|
|
|
|
environment. MAX_HEAP_SIZE is the total amount of memory dedicated
|
|
|
|
|
to the Java heap. HEAP_NEWSIZE refers to the size of the young
|
|
|
|
|
generation.
|
|
|
|
|
|
|
|
|
|
The main trade-off for the young generation is that the larger it
|
|
|
|
|
is, the longer GC pause times will be. The shorter it is, the more
|
|
|
|
|
expensive GC will be (usually).
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
heapNewSize = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
|
type = types.nullOr types.str;
|
2019-04-07 05:30:26 +01:00
|
|
|
|
default = null;
|
|
|
|
|
example = "800M";
|
|
|
|
|
description = ''
|
|
|
|
|
Must be left blank or set together with heapNewSize.
|
|
|
|
|
If left blank a sensible value for the available amount of RAM and CPU
|
|
|
|
|
cores is calculated.
|
|
|
|
|
|
|
|
|
|
Override to set the amount of memory to allocate to the JVM at
|
|
|
|
|
start-up. For production use you may wish to adjust this for your
|
|
|
|
|
environment. HEAP_NEWSIZE refers to the size of the young
|
|
|
|
|
generation.
|
|
|
|
|
|
|
|
|
|
The main trade-off for the young generation is that the larger it
|
|
|
|
|
is, the longer GC pause times will be. The shorter it is, the more
|
|
|
|
|
expensive GC will be (usually).
|
|
|
|
|
|
|
|
|
|
The example HEAP_NEWSIZE assumes a modern 8-core+ machine for decent pause
|
|
|
|
|
times. If in doubt, and if you do not particularly want to tweak, go with
|
|
|
|
|
100 MB per physical CPU core.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
mallocArenaMax = mkOption {
|
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
|
default = null;
|
|
|
|
|
example = 4;
|
|
|
|
|
description = ''
|
|
|
|
|
Set this to control the amount of arenas per-thread in glibc.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
remoteJmx = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Cassandra ships with JMX accessible *only* from localhost.
|
|
|
|
|
To enable remote JMX connections set to true.
|
|
|
|
|
|
|
|
|
|
Be sure to also enable authentication and/or TLS.
|
|
|
|
|
See: https://wiki.apache.org/cassandra/JmxSecurity
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
jmxPort = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 7199;
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies the default port over which Cassandra will be available for
|
|
|
|
|
JMX connections.
|
|
|
|
|
For security reasons, you should not expose this port to the internet.
|
|
|
|
|
Firewall it if needed.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2019-04-23 03:52:44 +01:00
|
|
|
|
jmxRoles = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
|
|
|
|
Roles that are allowed to access the JMX (e.g. nodetool)
|
2019-04-25 23:59:23 +01:00
|
|
|
|
BEWARE: The passwords will be stored world readable in the nix-store.
|
2019-04-26 00:13:09 +01:00
|
|
|
|
It's recommended to use your own protected file using
|
|
|
|
|
<literal>jmxRolesFile</literal>
|
2019-04-25 23:59:23 +01:00
|
|
|
|
|
|
|
|
|
Doesn't work in versions older than 3.11 because they don't like that
|
|
|
|
|
it's world readable.
|
2019-04-23 03:52:44 +01:00
|
|
|
|
'';
|
|
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
|
options = {
|
|
|
|
|
username = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
|
type = types.str;
|
2019-04-23 03:52:44 +01:00
|
|
|
|
description = "Username for JMX";
|
|
|
|
|
};
|
|
|
|
|
password = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
|
type = types.str;
|
2019-04-23 03:52:44 +01:00
|
|
|
|
description = "Password for JMX";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-04-25 23:59:23 +01:00
|
|
|
|
jmxRolesFile = mkOption {
|
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
|
default = if (lib.versionAtLeast cfg.package.version "3.11")
|
|
|
|
|
then pkgs.writeText "jmx-roles-file" defaultJmxRolesFile
|
|
|
|
|
else null;
|
|
|
|
|
example = "/var/lib/cassandra/jmx.password";
|
|
|
|
|
description = ''
|
|
|
|
|
Specify your own jmx roles file.
|
|
|
|
|
|
|
|
|
|
Make sure the permissions forbid "others" from reading the file if
|
|
|
|
|
you're using Cassandra below version 3.11.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2017-11-07 13:11:56 +00:00
|
|
|
|
};
|
2016-07-22 18:29:35 +01:00
|
|
|
|
|
2017-11-07 13:11:56 +00:00
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
assertions =
|
2019-04-07 05:30:26 +01:00
|
|
|
|
[ { assertion = (cfg.listenAddress == null) != (cfg.listenInterface == null);
|
2017-11-07 13:11:56 +00:00
|
|
|
|
message = "You have to set either listenAddress or listenInterface";
|
|
|
|
|
}
|
2019-04-07 05:30:26 +01:00
|
|
|
|
{ assertion = (cfg.rpcAddress == null) != (cfg.rpcInterface == null);
|
2017-11-07 13:11:56 +00:00
|
|
|
|
message = "You have to set either rpcAddress or rpcInterface";
|
|
|
|
|
}
|
2019-04-07 05:30:26 +01:00
|
|
|
|
{ assertion = (cfg.maxHeapSize == null) == (cfg.heapNewSize == null);
|
|
|
|
|
message = "If you set either of maxHeapSize or heapNewSize you have to set both";
|
|
|
|
|
}
|
2019-04-25 23:59:23 +01:00
|
|
|
|
{ assertion = cfg.remoteJmx -> cfg.jmxRolesFile != null;
|
|
|
|
|
message = ''
|
|
|
|
|
If you want JMX available remotely you need to set a password using
|
2019-04-26 00:13:09 +01:00
|
|
|
|
<literal>jmxRoles</literal> or <literal>jmxRolesFile</literal> if
|
|
|
|
|
using Cassandra older than v3.11.
|
2019-04-25 23:59:23 +01:00
|
|
|
|
'';
|
2019-04-23 03:52:44 +01:00
|
|
|
|
}
|
2016-07-22 18:29:35 +01:00
|
|
|
|
];
|
2017-11-07 13:11:56 +00:00
|
|
|
|
users = mkIf (cfg.user == defaultUser) {
|
2019-08-13 22:52:01 +01:00
|
|
|
|
extraUsers.${defaultUser} =
|
2017-11-07 13:11:56 +00:00
|
|
|
|
{ group = cfg.group;
|
|
|
|
|
home = cfg.homeDir;
|
|
|
|
|
createHome = true;
|
|
|
|
|
uid = config.ids.uids.cassandra;
|
|
|
|
|
description = "Cassandra service user";
|
|
|
|
|
};
|
2019-08-13 22:52:01 +01:00
|
|
|
|
extraGroups.${defaultUser}.gid = config.ids.gids.cassandra;
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
|
|
|
|
|
2017-11-07 13:11:56 +00:00
|
|
|
|
systemd.services.cassandra =
|
|
|
|
|
{ description = "Apache Cassandra service";
|
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
environment =
|
|
|
|
|
{ CASSANDRA_CONF = "${cassandraEtc}";
|
2019-04-23 03:52:44 +01:00
|
|
|
|
JVM_OPTS = builtins.concatStringsSep " " fullJvmOptions;
|
2019-04-07 05:30:26 +01:00
|
|
|
|
MAX_HEAP_SIZE = toString cfg.maxHeapSize;
|
|
|
|
|
HEAP_NEWSIZE = toString cfg.heapNewSize;
|
|
|
|
|
MALLOC_ARENA_MAX = toString cfg.mallocArenaMax;
|
|
|
|
|
LOCAL_JMX = if cfg.remoteJmx then "no" else "yes";
|
|
|
|
|
JMX_PORT = toString cfg.jmxPort;
|
2017-11-07 13:11:56 +00:00
|
|
|
|
};
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
serviceConfig =
|
|
|
|
|
{ User = cfg.user;
|
|
|
|
|
Group = cfg.group;
|
|
|
|
|
ExecStart = "${cfg.package}/bin/cassandra -f";
|
|
|
|
|
SuccessExitStatus = 143;
|
|
|
|
|
};
|
|
|
|
|
};
|
2016-07-22 18:29:35 +01:00
|
|
|
|
|
2017-11-07 13:11:56 +00:00
|
|
|
|
systemd.services.cassandra-full-repair =
|
|
|
|
|
{ description = "Perform a full repair on this Cassandra node";
|
|
|
|
|
after = [ "cassandra.service" ];
|
|
|
|
|
requires = [ "cassandra.service" ];
|
|
|
|
|
serviceConfig =
|
|
|
|
|
{ User = cfg.user;
|
|
|
|
|
Group = cfg.group;
|
|
|
|
|
ExecStart =
|
|
|
|
|
lib.concatStringsSep " "
|
|
|
|
|
([ "${cfg.package}/bin/nodetool" "repair" "--full"
|
|
|
|
|
] ++ cfg.fullRepairOptions);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
systemd.timers.cassandra-full-repair =
|
2019-04-24 04:48:22 +01:00
|
|
|
|
mkIf (cfg.fullRepairInterval != null) {
|
2017-11-07 13:11:56 +00:00
|
|
|
|
description = "Schedule full repairs on Cassandra";
|
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig =
|
|
|
|
|
{ OnBootSec = cfg.fullRepairInterval;
|
|
|
|
|
OnUnitActiveSec = cfg.fullRepairInterval;
|
|
|
|
|
Persistent = true;
|
|
|
|
|
};
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
|
|
|
|
|
2017-11-07 13:11:56 +00:00
|
|
|
|
systemd.services.cassandra-incremental-repair =
|
|
|
|
|
{ description = "Perform an incremental repair on this cassandra node.";
|
|
|
|
|
after = [ "cassandra.service" ];
|
|
|
|
|
requires = [ "cassandra.service" ];
|
|
|
|
|
serviceConfig =
|
|
|
|
|
{ User = cfg.user;
|
|
|
|
|
Group = cfg.group;
|
|
|
|
|
ExecStart =
|
|
|
|
|
lib.concatStringsSep " "
|
|
|
|
|
([ "${cfg.package}/bin/nodetool" "repair"
|
|
|
|
|
] ++ cfg.incrementalRepairOptions);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
systemd.timers.cassandra-incremental-repair =
|
2019-04-24 04:48:22 +01:00
|
|
|
|
mkIf (cfg.incrementalRepairInterval != null) {
|
2017-11-07 13:11:56 +00:00
|
|
|
|
description = "Schedule incremental repairs on Cassandra";
|
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig =
|
|
|
|
|
{ OnBootSec = cfg.incrementalRepairInterval;
|
|
|
|
|
OnUnitActiveSec = cfg.incrementalRepairInterval;
|
|
|
|
|
Persistent = true;
|
|
|
|
|
};
|
2016-07-22 18:29:35 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|