2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ...}:
|
2021-10-28 06:52:43 +00:00
|
|
|
with lib;
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.hadoop;
|
2021-10-28 06:52:43 +00:00
|
|
|
hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
|
|
|
|
restartIfChanged = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Automatically restart the service on config change.
|
|
|
|
This can be set to false to defer restarts on clusters running critical applications.
|
|
|
|
Please consider the security implications of inadvertently running an older version,
|
|
|
|
and the possibility of unexpected behavior caused by inconsistent versions across a cluster when disabling this option.
|
|
|
|
'';
|
|
|
|
default = false;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.hadoop.hdfs = {
|
2021-10-28 06:52:43 +00:00
|
|
|
namenode = {
|
|
|
|
enabled = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the HDFS NameNode
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
inherit restartIfChanged;
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Open firewall ports for namenode
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
datanode = {
|
|
|
|
enabled = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the HDFS DataNode
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
inherit restartIfChanged;
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Open firewall ports for datanode
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
(mkIf cfg.hdfs.namenode.enabled {
|
|
|
|
systemd.services.hdfs-namenode = {
|
|
|
|
description = "Hadoop HDFS NameNode";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-28 06:52:43 +00:00
|
|
|
inherit (cfg.hdfs.namenode) restartIfChanged;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
${cfg.package}/bin/hdfs --config ${hadoopConf} namenode -format -nonInteractive || true
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "hdfs";
|
|
|
|
SyslogIdentifier = "hdfs-namenode";
|
|
|
|
ExecStart = "${cfg.package}/bin/hdfs --config ${hadoopConf} namenode";
|
2021-10-28 06:52:43 +00:00
|
|
|
Restart = "always";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = (mkIf cfg.hdfs.namenode.openFirewall [
|
|
|
|
9870 # namenode.http-address
|
|
|
|
8020 # namenode.rpc-address
|
|
|
|
]);
|
2020-04-24 23:36:52 +00:00
|
|
|
})
|
|
|
|
(mkIf cfg.hdfs.datanode.enabled {
|
|
|
|
systemd.services.hdfs-datanode = {
|
|
|
|
description = "Hadoop HDFS DataNode";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-28 06:52:43 +00:00
|
|
|
inherit (cfg.hdfs.datanode) restartIfChanged;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "hdfs";
|
|
|
|
SyslogIdentifier = "hdfs-datanode";
|
|
|
|
ExecStart = "${cfg.package}/bin/hdfs --config ${hadoopConf} datanode";
|
2021-10-28 06:52:43 +00:00
|
|
|
Restart = "always";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = (mkIf cfg.hdfs.datanode.openFirewall [
|
|
|
|
9864 # datanode.http.address
|
|
|
|
9866 # datanode.address
|
|
|
|
9867 # datanode.ipc.address
|
|
|
|
]);
|
2020-04-24 23:36:52 +00:00
|
|
|
})
|
|
|
|
(mkIf (
|
|
|
|
cfg.hdfs.namenode.enabled || cfg.hdfs.datanode.enabled
|
|
|
|
) {
|
|
|
|
users.users.hdfs = {
|
|
|
|
description = "Hadoop HDFS user";
|
|
|
|
group = "hadoop";
|
|
|
|
uid = config.ids.uids.hdfs;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|