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.yarn = {
|
2021-10-28 06:52:43 +00:00
|
|
|
|
resourcemanager = {
|
2021-12-06 16:07:01 +00:00
|
|
|
|
enable = mkEnableOption "Whether to run the Hadoop YARN ResourceManager";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
inherit restartIfChanged;
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Open firewall ports for resourcemanager
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
|
nodemanager = {
|
2021-12-06 16:07:01 +00:00
|
|
|
|
enable = mkEnableOption "Whether to run the Hadoop YARN NodeManager";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
inherit restartIfChanged;
|
|
|
|
|
addBinBash = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Add /bin/bash. This is needed by the linux container executor's launch script.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Open firewall ports for nodemanager.
|
|
|
|
|
Because containers can listen on any ephemeral port, TCP ports 1024–65535 will be opened.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
|
(mkIf (
|
2021-12-06 16:07:01 +00:00
|
|
|
|
cfg.yarn.resourcemanager.enable || cfg.yarn.nodemanager.enable
|
2020-04-24 23:36:52 +00:00
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
users.users.yarn = {
|
|
|
|
|
description = "Hadoop YARN user";
|
|
|
|
|
group = "hadoop";
|
|
|
|
|
uid = config.ids.uids.yarn;
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
(mkIf cfg.yarn.resourcemanager.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.services.yarn-resourcemanager = {
|
|
|
|
|
description = "Hadoop YARN ResourceManager";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-28 06:52:43 +00:00
|
|
|
|
inherit (cfg.yarn.resourcemanager) restartIfChanged;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = "yarn";
|
|
|
|
|
SyslogIdentifier = "yarn-resourcemanager";
|
|
|
|
|
ExecStart = "${cfg.package}/bin/yarn --config ${hadoopConf} " +
|
|
|
|
|
" resourcemanager";
|
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.yarn.resourcemanager.openFirewall [
|
|
|
|
|
8088 # resourcemanager.webapp.address
|
|
|
|
|
8030 # resourcemanager.scheduler.address
|
|
|
|
|
8031 # resourcemanager.resource-tracker.address
|
|
|
|
|
8032 # resourcemanager.address
|
2021-12-06 16:07:01 +00:00
|
|
|
|
8033 # resourcemanager.admin.address
|
2021-10-28 06:52:43 +00:00
|
|
|
|
]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
})
|
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
(mkIf cfg.yarn.nodemanager.enable {
|
2021-10-28 06:52:43 +00:00
|
|
|
|
# Needed because yarn hardcodes /bin/bash in container start scripts
|
|
|
|
|
# These scripts can't be patched, they are generated at runtime
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
|
(mkIf cfg.yarn.nodemanager.addBinBash "L /bin/bash - - - - /run/current-system/sw/bin/bash")
|
|
|
|
|
];
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.services.yarn-nodemanager = {
|
|
|
|
|
description = "Hadoop YARN NodeManager";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-28 06:52:43 +00:00
|
|
|
|
inherit (cfg.yarn.nodemanager) restartIfChanged;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
|
preStart = ''
|
|
|
|
|
# create log dir
|
|
|
|
|
mkdir -p /var/log/hadoop/yarn/nodemanager
|
|
|
|
|
chown yarn:hadoop /var/log/hadoop/yarn/nodemanager
|
|
|
|
|
|
|
|
|
|
# set up setuid container executor binary
|
|
|
|
|
rm -rf /run/wrappers/yarn-nodemanager/ || true
|
|
|
|
|
mkdir -p /run/wrappers/yarn-nodemanager/{bin,etc/hadoop}
|
|
|
|
|
cp ${cfg.package}/lib/${cfg.package.untarDir}/bin/container-executor /run/wrappers/yarn-nodemanager/bin/
|
|
|
|
|
chgrp hadoop /run/wrappers/yarn-nodemanager/bin/container-executor
|
|
|
|
|
chmod 6050 /run/wrappers/yarn-nodemanager/bin/container-executor
|
|
|
|
|
cp ${hadoopConf}/container-executor.cfg /run/wrappers/yarn-nodemanager/etc/hadoop/
|
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = "yarn";
|
|
|
|
|
SyslogIdentifier = "yarn-nodemanager";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
PermissionsStartOnly = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
ExecStart = "${cfg.package}/bin/yarn --config ${hadoopConf} " +
|
|
|
|
|
" nodemanager";
|
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.allowedTCPPortRanges = [
|
|
|
|
|
(mkIf (cfg.yarn.nodemanager.openFirewall) {from = 1024; to = 65535;})
|
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
}
|