git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #49348 from markuskowa/mod-slurm-upgrade

nixos/slurm: add slurmdbd, run daemons as user

commit6efd811062849402f1f44952fd5d7cd283d72baf authorxeji <36407913+xeji@users.noreply.github.com> dateWed 31 Oct 2018, 00:16 (8 years ago) parent933874eb388bee
4 files changed+174−21
nixos/doc/manual/release-notes/rl-1903.xml+20 nixos/modules/misc/ids.nix+2 nixos/modules/services/computing/slurm/slurm.nix+102−11 nixos/tests/slurm.nix+50−10
nixos/doc/manual/release-notes/rl-1903.xml+20
@@ -152,6 +152,26 @@
152152 has been renamed to <varname>postgresql_9_6</varname>.
153153 </para>
154154 </listitem>
155+ <listitem>
156+ <para>
157+ Slurm introduces the new option
158+ <literal>services.slurm.stateSaveLocation</literal>,
159+ which is now set to <literal>/var/spool/slurm</literal> by default
160+ (instead of <literal>/var/spool</literal>).
161+ Make sure to move all files to the new directory or to set the option accordingly.
162+ </para>
163+ <para>
164+ The slurmctld now runs as user <literal>slurm</literal> instead of <literal>root</literal>.
165+ If you want to keep slurmctld running as <literal>root</literal>, set
166+ <literal>services.slurm.user = root</literal>.
167+ </para>
168+ <para>
169+ The options <literal>services.slurm.nodeName</literal> and
170+ <literal>services.slurm.partitionName</literal> are now sets of
171+ strings to correctly reflect that fact that each of these
172+ options can occour more than once in the configuration.
173+ </para>
174+ </listitem>
155175 </itemizedlist>
156176 </section>
157177
nixos/modules/misc/ids.nix+2
@@ -331,6 +331,7 @@
331331 zeronet = 304;
332332 lirc = 305;
333333 lidarr = 306;
334+ slurm = 307;
334335
335336 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
336337
@@ -622,6 +623,7 @@
622623 zeronet = 304;
623624 lirc = 305;
624625 lidarr = 306;
626+ slurm = 307;
625627
626628 # When adding a gid, make sure it doesn't match an existing
627629 # uid. Users and groups with the same name should have equal
nixos/modules/services/computing/slurm/slurm.nix+102−11
@@ -6,13 +6,18 @@ let
66
77 cfg = config.services.slurm;
88 # configuration file can be generated by http://slurm.schedmd.com/configurator.html
9+
10+ defaultUser = "slurm";
11+
912 configFile = pkgs.writeTextDir "slurm.conf"
1013 ''
1114 ClusterName=${cfg.clusterName}
15+ StateSaveLocation=${cfg.stateSaveLocation}
16+ SlurmUser=${cfg.user}
1217 ${optionalString (cfg.controlMachine != null) ''controlMachine=${cfg.controlMachine}''}
1318 ${optionalString (cfg.controlAddr != null) ''controlAddr=${cfg.controlAddr}''}
14− ${optionalString (cfg.nodeName != null) ''nodeName=${cfg.nodeName}''}
15− ${optionalString (cfg.partitionName != null) ''partitionName=${cfg.partitionName}''}
19+ ${toString (map (x: "NodeName=${x}\n") cfg.nodeName)}
20+ ${toString (map (x: "PartitionName=${x}\n") cfg.partitionName)}
1621 PlugStackConfig=${plugStackConfig}
1722 ProctrackType=${cfg.procTrackType}
1823 ${cfg.extraConfig}
@@ -24,12 +29,19 @@ let
2429 ${cfg.extraPlugstackConfig}
2530 '';
2631
27−
2832 cgroupConfig = pkgs.writeTextDir "cgroup.conf"
2933 ''
3034 ${cfg.extraCgroupConfig}
3135 '';
3236
37+ slurmdbdConf = pkgs.writeTextDir "slurmdbd.conf"
38+ ''
39+ DbdHost=${cfg.dbdserver.dbdHost}
40+ SlurmUser=${cfg.user}
41+ StorageType=accounting_storage/mysql
42+ ${cfg.dbdserver.extraConfig}
43+ '';
44+
3345 # slurm expects some additional config files to be
3446 # in the same directory as slurm.conf
3547 etcSlurm = pkgs.symlinkJoin {
@@ -43,6 +55,8 @@ in
4355
4456 ###### interface
4557
58+ meta.maintainers = [ maintainers.markuskowa ];
59+
4660 options = {
4761
4862 services.slurm = {
@@ -60,6 +74,27 @@ in
6074 };
6175 };
6276
77+ dbdserver = {
78+ enable = mkEnableOption "SlurmDBD service";
79+
80+ dbdHost = mkOption {
81+ type = types.str;
82+ default = config.networking.hostName;
83+ description = ''
84+ Hostname of the machine where <literal>slurmdbd</literal>
85+ is running (i.e. name returned by <literal>hostname -s</literal>).
86+ '';
87+ };
88+
89+ extraConfig = mkOption {
90+ type = types.lines;
91+ default = "";
92+ description = ''
93+ Extra configuration for <literal>slurmdbd.conf</literal>
94+ '';
95+ };
96+ };
97+
6398 client = {
6499 enable = mkEnableOption "slurm client daemon";
65100 };
@@ -116,9 +151,9 @@ in
116151 };
117152
118153 nodeName = mkOption {
119− type = types.nullOr types.str;
120− default = null;
121− example = "linux[1-32] CPUs=1 State=UNKNOWN";
154+ type = types.listOf types.str;
155+ default = [];
156+ example = literalExample ''[ "linux[1-32] CPUs=1 State=UNKNOWN" ];'';
122157 description = ''
123158 Name that SLURM uses to refer to a node (or base partition for BlueGene
124159 systems). Typically this would be the string that "/bin/hostname -s"
@@ -127,9 +162,9 @@ in
127162 };
128163
129164 partitionName = mkOption {
130− type = types.nullOr types.str;
131− default = null;
132− example = "debug Nodes=linux[1-32] Default=YES MaxTime=INFINITE State=UP";
165+ type = types.listOf types.str;
166+ default = [];
167+ example = literalExample ''[ "debug Nodes=linux[1-32] Default=YES MaxTime=INFINITE State=UP" ];'';
133168 description = ''
134169 Name by which the partition may be referenced. Note that now you have
135170 to write the partition's parameters after the name.
@@ -150,7 +185,7 @@ in
150185 };
151186
152187 procTrackType = mkOption {
153− type = types.string;
188+ type = types.str;
154189 default = "proctrack/linuxproc";
155190 description = ''
156191 Plugin to be used for process tracking on a job step basis.
@@ -159,6 +194,25 @@ in
159194 '';
160195 };
161196
197+ stateSaveLocation = mkOption {
198+ type = types.str;
199+ default = "/var/spool/slurmctld";
200+ description = ''
201+ Directory into which the Slurm controller, slurmctld, saves its state.
202+ '';
203+ };
204+
205+ user = mkOption {
206+ type = types.str;
207+ default = defaultUser;
208+ description = ''
209+ Set this option when you want to run the slurmctld daemon
210+ as something else than the default slurm user "slurm".
211+ Note that the UID of this user needs to be the same
212+ on all nodes.
213+ '';
214+ };
215+
162216 extraConfig = mkOption {
163217 default = "";
164218 type = types.lines;
@@ -184,6 +238,8 @@ in
184238 used when <literal>procTrackType=proctrack/cgroup</literal>.
185239 '';
186240 };
241+
242+
187243 };
188244
189245 };
@@ -220,12 +276,24 @@ in
220276 '';
221277 };
222278
223− in mkIf (cfg.enableStools || cfg.client.enable || cfg.server.enable) {
279+ in mkIf ( cfg.enableStools ||
280+ cfg.client.enable ||
281+ cfg.server.enable ||
282+ cfg.dbdserver.enable ) {
224283
225284 environment.systemPackages = [ wrappedSlurm ];
226285
227286 services.munge.enable = mkDefault true;
228287
288+ # use a static uid as default to ensure it is the same on all nodes
289+ users.users.slurm = mkIf (cfg.user == defaultUser) {
290+ name = defaultUser;
291+ group = "slurm";
292+ uid = config.ids.uids.slurm;
293+ };
294+
295+ users.groups.slurm.gid = config.ids.uids.slurm;
296+
229297 systemd.services.slurmd = mkIf (cfg.client.enable) {
230298 path = with pkgs; [ wrappedSlurm coreutils ]
231299 ++ lib.optional cfg.enableSrunX11 slurm-spank-x11;
@@ -261,6 +329,29 @@ in
261329 PIDFile = "/run/slurmctld.pid";
262330 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
263331 };
332+
333+ preStart = ''
334+ mkdir -p ${cfg.stateSaveLocation}
335+ chown -R ${cfg.user}:slurm ${cfg.stateSaveLocation}
336+ '';
337+ };
338+
339+ systemd.services.slurmdbd = mkIf (cfg.dbdserver.enable) {
340+ path = with pkgs; [ wrappedSlurm munge coreutils ];
341+
342+ wantedBy = [ "multi-user.target" ];
343+ after = [ "network.target" "munged.service" "mysql.service" ];
344+ requires = [ "munged.service" "mysql.service" ];
345+
346+ # slurm strips the last component off the path
347+ environment.SLURM_CONF = "${slurmdbdConf}/slurm.conf";
348+
349+ serviceConfig = {
350+ Type = "forking";
351+ ExecStart = "${cfg.package}/bin/slurmdbd";
352+ PIDFile = "/run/slurmdbd.pid";
353+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
354+ };
264355 };
265356
266357 };
nixos/tests/slurm.nix+50−10
@@ -1,22 +1,27 @@
1−import ./make-test.nix ({ ... }:
2−let mungekey = "mungeverryweakkeybuteasytointegratoinatest";
1+import ./make-test.nix ({ lib, ... }:
2+let
3+ mungekey = "mungeverryweakkeybuteasytointegratoinatest";
4+
35 slurmconfig = {
46 controlMachine = "control";
5− nodeName = ''
6− control
7− NodeName=node[1-3] CPUs=1 State=UNKNOWN
7+ nodeName = [ "node[1-3] CPUs=1 State=UNKNOWN" ];
8+ partitionName = [ "debug Nodes=node[1-3] Default=YES MaxTime=INFINITE State=UP" ];
9+ extraConfig = ''
10+ AccountingStorageHost=dbd
11+ AccountingStorageType=accounting_storage/slurmdbd
812 '';
9− partitionName = "debug Nodes=node[1-3] Default=YES MaxTime=INFINITE State=UP";
1013 };
1114in {
1215 name = "slurm";
1316
17+ meta.maintainers = [ lib.maintainers.markuskowa ];
18+
1419 nodes =
1520 let
1621 computeNode =
1722 { ...}:
1823 {
19− # TODO slrumd port and slurmctld port should be configurations and
24+ # TODO slurmd port and slurmctld port should be configurations and
2025 # automatically allowed by the firewall.
2126 networking.firewall.enable = false;
2227 services.slurm = {
@@ -43,6 +48,24 @@ in {
4348 } // slurmconfig;
4449 };
4550
51+ dbd =
52+ { pkgs, ... } :
53+ {
54+ networking.firewall.enable = false;
55+ services.slurm.dbdserver = {
56+ enable = true;
57+ };
58+ services.mysql = {
59+ enable = true;
60+ package = pkgs.mysql;
61+ ensureDatabases = [ "slurm_acct_db" ];
62+ ensureUsers = [{
63+ ensurePermissions = { "slurm_acct_db.*" = "ALL PRIVILEGES"; };
64+ name = "slurm";
65+ }];
66+ };
67+ };
68+
4669 node1 = computeNode;
4770 node2 = computeNode;
4871 node3 = computeNode;
@@ -54,7 +77,7 @@ in {
5477 startAll;
5578
5679 # Set up authentification across the cluster
57− foreach my $node (($submit,$control,$node1,$node2,$node3))
80+ foreach my $node (($submit,$control,$dbd,$node1,$node2,$node3))
5881 {
5982 $node->waitForUnit("default.target");
6083
@@ -63,10 +86,22 @@ in {
6386 $node->succeed("chmod 0400 /etc/munge/munge.key");
6487 $node->succeed("chown munge:munge /etc/munge/munge.key");
6588 $node->succeed("systemctl restart munged");
66− }
89+
90+ $node->waitForUnit("munged");
91+ };
6792
6893 # Restart the services since they have probably failed due to the munge init
6994 # failure
95+ subtest "can_start_slurmdbd", sub {
96+ $dbd->succeed("systemctl restart slurmdbd");
97+ $dbd->waitForUnit("slurmdbd.service");
98+ };
99+
100+ # there needs to be an entry for the current
101+ # cluster in the database before slurmctld is restarted
102+ subtest "add_account", sub {
103+ $control->succeed("sacctmgr -i add cluster default");
104+ };
70105
71106 subtest "can_start_slurmctld", sub {
72107 $control->succeed("systemctl restart slurmctld");
@@ -81,12 +116,17 @@ in {
81116 }
82117 };
83118
84− # Test that the cluster work and can distribute jobs;
119+ # Test that the cluster works and can distribute jobs;
85120
86121 subtest "run_distributed_command", sub {
87122 # Run `hostname` on 3 nodes of the partition (so on all the 3 nodes).
88123 # The output must contain the 3 different names
89124 $submit->succeed("srun -N 3 hostname | sort | uniq | wc -l | xargs test 3 -eq");
90125 };
126+
127+ subtest "check_slurm_dbd", sub {
128+ # find the srun job from above in the database
129+ $submit->succeed("sacct | grep hostname");
130+ };
91131 '';
92132})