-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_local.pl
executable file
·459 lines (388 loc) · 11.7 KB
/
setup_local.pl
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#!/usr/bin/perl -w
###############################################################################
# Written by Brian Christiansen <brian@schedmd.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
# Sets up multiple slurm clusters on the same box using different ports.
#
# Builds/expects the following heirarchy:
# ${prefix}/slurm -- source
# ${prefix}/fed1 -- cluster config files and binaries
# ${prefix}/fed2 -- cluster config files and binaries
# ${prefix}/fed3 -- cluster config files and binaries
###############################################################################
use strict;
use Getopt::Long;
my $ACCT_PORT = 30000;
my $BASE_PORT = 30001;
my $CLUSTER_PREFIX = "c";
my $DB_USER = "";
my $DB_PASSWD = "";
my $GIT_BRANCH = "master";
my $GIT_REPO = "https://github.com/SchedMD/slurm.git";
my $NUM_CLUSTERS = 3;
my $SLURM_DB_NAME = "slurm_fed";
my $user = `whoami`;
chomp($user);
my $RUN_TESTS = 0;
my $opt_prefix = "$ENV{HOME}/slurm/federation/";
my $opt_help;
my $full_prefix; # Expanded full path of prefix.
my $usage =<<"END";
USAGE: $0
--branch=<name> name of branch to clone (default: master)
--prefix=<prefix> where to setup federation configuration [$opt_prefix]
--runtests run federation expect tests
--help print this message
END
GetOptions("branch=s" => \$GIT_BRANCH,
"prefix=s" => \$opt_prefix,
"runtests" => \$RUN_TESTS,
"help" => \$opt_help)
or die($usage);
if (defined $opt_help) {
print $usage;
exit 1;
}
print "Creating prefix: $opt_prefix\n";
die "Failed to create $opt_prefix: $!" if system("mkdir -p $opt_prefix");
chdir $opt_prefix or die "Couldn't chdir to $opt_prefix: $!";
$full_prefix = `pwd`; # Get full path
chomp($full_prefix);
print "\n";
while (!-d "$full_prefix/slurm") {
print "I don't see a $full_prefix/slurm directory containing the slurm src.\n";
print "Should I get the slurm source from github? [y|n]";
my $answer = <STDIN>;
if ($answer =~ m/[yY]/) {
die "Couldn't get src: $!" if system("git clone -b $GIT_BRANCH $GIT_REPO");
} else {
print "Ok, put the src in $full_prefix/slurm\n";
print "Hit enter when done.\n";
$answer = <STDIN>;
}
}
print "\n\n";
print "Start Env Setup\n";
for (1..$NUM_CLUSTERS) {
my $pid;
my $cname = get_cluster_name($_);
unless ($pid = fork()) {
print "$cname: setting up env\n";
setup_env($_);
print "$cname: running configure\n";
configure_src($_);
print "$cname: env and configure done\n";
exit 0;
}
}
while (my $pid = wait() != -1) {
my $rc = $? >> 8;
die "ERROR: forked pid:$pid returned an error (rc:$rc): $!" if ($?);
}
print "Install html seprately\n";
for (1..$NUM_CLUSTERS) {
chdir($full_prefix);
my $cname = get_cluster_name($_);
print "$cname: installing html\n";
install_html($_);
print "$cname: done installing html\n";
}
print "Install rest of binaries in parallel\n";
for (1..$NUM_CLUSTERS) {
my $pid;
my $cname = get_cluster_name($_);
unless ($pid = fork()) {
print "$cname: building and installing binaries\n";
install_src($_);
print "$cname: done installing binaries\n";
exit 0;
}
print "Done Setting up " . get_cluster_name($_) . "\n";
}
while (my $pid = wait() != -1) {
my $rc = $? >> 8;
die "ERROR: forked pid:$pid returned an error (rc:$rc): $!" if ($?);
}
print "Env Setup Done\n\n";
print "Starting Daemons\n";
for (1..$NUM_CLUSTERS) {
start_dbd($_) if ($_ == 1);
my $cname = get_cluster_name($_);
print "$cname: adding cluster to dbd\n";
run_cmd_expect_error("$full_prefix/$cname/bin/sacctmgr -i add cluster $cname",
"This cluster $cname already exists. Not adding.");
if ($_ == $NUM_CLUSTERS) {
run_cmd_expect_error("$full_prefix/$cname/bin/sacctmgr -i add account tacct", "Nothing new added.");
run_cmd_expect_error("$full_prefix/$cname/bin/sacctmgr -i add user $user account=tacct", "Nothing new added");
run_cmd("$full_prefix/$cname/bin/sacctmgr -i mod user $user set admin=admin");
}
}
for (1..$NUM_CLUSTERS) {
my $cname = get_cluster_name($_);
print "$cname: starting ctld\n";
start_ctld($_);
print "$cname: starting slurmds\n";
start_slurmds($_);
print "$cname: done starting daemons\n";
}
print "Done starting all daemons\n\n";
my $exit_code = 0;
if ($RUN_TESTS) {
my $test_cname = get_cluster_name(1);
print "Running regression tests\n";
my $test_dir = "$full_prefix/slurm/testsuite/expect";
$ENV{SLURM_LOCAL_GLOBALS_FILE} = "$test_dir/globals.$test_cname";
chdir $test_dir or die "Couldn't chdir to $test_dir: $!";
$exit_code = run_cmd("./regression.py --include=test22.1,test37.*", 1);
print "\nDone running tests!\n";
print "But some tests failed\n" if $exit_code;
print "\n\n";
}
print <<"END";
You can now interact with the setup.
See the README for information and examples on how to interact with the setup.
END
exit $exit_code;
################
# Routines
################
sub run_cmd
{
my $cmd = shift;
my $ignore = shift;
print "cmd: $cmd\n";
my $rc = system($cmd);
die "ERROR: running $cmd: $!" if (!$ignore && $rc);
return $rc >> 8;
}
sub run_cmd_expect_error
{
my $cmd = shift;
my $expected_error = shift;
print "cmd: $cmd\n";
my $output = `$cmd`;
if (($? >> 8) && !($output =~ m/$expected_error/)) {
die "ERROR: running $cmd: $!";
}
}
sub setup_env
{
my $index = shift;
my $cname = get_cluster_name($index);
chdir $full_prefix or die "Couldn't chdir to $full_prefix $!";
print "Setting up $cname\n";
my $loc_port = $BASE_PORT + (1000 * $index);
run_cmd("mkdir -p $cname/state");
run_cmd("mkdir -p $cname/spool");
run_cmd("mkdir -p $cname/run");
run_cmd("mkdir -p $cname/log");
run_cmd("mkdir -p $cname/slurm");
run_cmd("mkdir -p $cname/etc");
# slurm.conf
open FILE, ">$cname/etc/slurm.conf" or die "Couldn't create slurm.conf: $!";
print FILE make_slurm_conf($cname, $loc_port);
close FILE;
# slurmdbd.conf
open FILE, ">$cname/etc/slurmdbd.conf" or die "Couldn't create slurmdbd.conf: $!";
print FILE make_slurmdbd_conf($cname);
close FILE;
run_cmd("chmod 600 $cname/etc/slurmdbd.conf", 0);
# globals.local
open FILE, ">$full_prefix/slurm/testsuite/expect/globals.$cname" or die "Couldn't create globals.$cname $!";
print FILE <<"END";
set my_slurm_base "$opt_prefix"
set src_dir "\$my_slurm_base/slurm"
set slurm_dir "\$my_slurm_base/$cname"
set build_dir "\$slurm_dir/slurm"
set partition "debug"
set fed_slurm_base "\$my_slurm_base"
set fedc1 "c1"
set fedc2 "c2"
set fedc3 "c3"
END
close FILE;
}
sub get_cluster_name
{
my $index = shift;
return "$CLUSTER_PREFIX$index";
}
sub get_src_loc
{
return "$full_prefix/slurm";
}
sub configure_src
{
my $index = shift;
my $cname = get_cluster_name($index);
my $src_loc = get_src_loc();
chdir "$full_prefix/$cname/slurm" or die "Couldn't chdir to $full_prefix/$cname/slurm: $!";
print run_cmd("$src_loc/configure --prefix=$full_prefix/$cname \\
--enable-multiple-slurmd \\
--enable-developer \\
>/dev/null");
}
sub install_src
{
my $index = shift;
my $cname = get_cluster_name($index);
chdir "$full_prefix/$cname/slurm" or die "Couldn't chdir to $full_prefix/$cname/slurm: $!";
print run_cmd("make -j install >/dev/null")
}
sub install_html
{
my $index = shift;
my $cname = get_cluster_name($index);
chdir "$full_prefix/$cname/slurm/doc" or die "Couldn't chdir to $full_prefix/$cname/slurm: $!";
print run_cmd("make -j install >/dev/null");
chdir $full_prefix;
}
sub start_dbd
{
my $index = shift;
my $cname = get_cluster_name($index);
print run_cmd("$full_prefix/$cname/sbin/slurmdbd");
sleep 2;
my $pid_file = "$full_prefix/$cname/run/slurmdbd.pid";
die "$pid_file doesn't exist: $!" unless (-f $pid_file);
my $dbd_pid = `cat $pid_file`;
chomp $dbd_pid;
die "dbd pid pid not found" unless (kill 0, $dbd_pid);
#verify it's up
my $dbd_resp = 0;
for (1..3) {
sleep 2;
my $output = `$full_prefix/$cname/bin/sacctmgr show config`;
if ($output =~ m/^Configuration data as/) {
$dbd_resp = 1;
last;
}
print "ERROR: dbd not responding. Will wait a sec and if it comes up\n"
}
die "ERROR: dbd not responding." if (!$dbd_resp);
print "$full_prefix/$cname/sbin/slurmdbd started\n";
}
sub start_ctld
{
my $index = shift;
my $cname = get_cluster_name($index);
print run_cmd("$full_prefix/$cname/sbin/slurmctld");
sleep 2;
my $pid_file = "$full_prefix/$cname/run/slurmctld.pid";
die "$pid_file doesn't exist: $!" unless (-f $pid_file);
my $ctld_pid = `cat $pid_file`;
chomp $ctld_pid;
print "$full_prefix/$cname/sbin/slurmctld started\n";
}
sub start_slurmds
{
my $index = shift;
my $cname = get_cluster_name($index);
for (1..10) {
my $node = "${cname}_$_";
my $cmd = "$full_prefix/$cname/sbin/slurmd -N $node";
print run_cmd($cmd);
sleep 2;
my $pid_file = "$full_prefix/$cname/run/slurmd-$node.pid";
die "$pid_file doesn't exist: $!" unless (-f $pid_file);
my $node_pid = `cat $pid_file`;
chomp $node_pid;
die "$node pid not found" unless (kill 0, $node_pid);
print "$full_prefix/$cname/sbin/slurmd ($node) started\n";
}
}
sub make_slurm_conf
{
my $cname = shift;
my $loc_port = shift;
my $ctld_port = $loc_port++;
my $host_ports = $loc_port . "-" . ($loc_port+9);
my $conf =<<"END";
ClusterName=$cname
ControlMachine=localhost
AuthType=auth/munge
AuthInfo=cred_expire=30 #quicker requeue time
CacheGroups=0
CryptoType=crypto/munge
MpiDefault=none
ProctrackType=proctrack/pgid
SlurmctldPidFile=$full_prefix/$cname/run/slurmctld.pid
SlurmctldPort=$ctld_port
SlurmdPidFile=$full_prefix/$cname/run/slurmd-%n.pid
SlurmdSpoolDir=$full_prefix/$cname/spool/slurmd-%n
SlurmUser=$user
SlurmdUser=$user
StateSaveLocation=$full_prefix/$cname/state
SwitchType=switch/none
TaskPlugin=affinity
InactiveLimit=0
KillWait=30
MessageTimeout=60
MinJobAge=300
SlurmctldTimeout=120
SlurmdTimeout=30
Waittime=0
DefMemPerCPU=100
SchedulerType=sched/backfill
SelectType=select/cons_res
SelectTypeParameters=CR_CORE_Memory
PriorityType=priority/multifactor
AccountingStorageEnforce=associations,limits,qos,safe
AccountingStorageHost=localhost
AccountingStoragePort=$ACCT_PORT
AccountingStorageType=accounting_storage/slurmdbd
AccountingStoreJobComment=YES
SlurmdParameters=config_overrides
JobAcctGatherType=jobacct_gather/linux
SlurmctldDebug=info
SlurmctldLogFile=$full_prefix/$cname/log/slurmctld.log
SlurmdDebug=debug
SlurmdLogFile=$full_prefix/$cname/log/slurmd-%n.log
DebugFlags=protocol,federation
LogTimeFormat=thread_id
NodeName=DEFAULT CPUs=8 Sockets=1 CoresPerSocket=4 ThreadsPerCore=2 State=UNKNOWN RealMemory=7830
NodeName=${cname}_[1-10] NodeAddr=localhost Port=$host_ports
PartitionName=debug Nodes=${cname}_[1-10] Default=YES MaxTime=INFINITE State=UP
RequeueExit=5
RequeueExitHold=6
FederationParameters=fed_display
END
return $conf
}
sub make_slurmdbd_conf
{
my $cname = shift;
my $conf =<<"END";
AuthType=auth/munge
DbdHost=localhost
DbdPort=$ACCT_PORT
DebugFlags=FEDERATION
DebugLevel=info
LogFile=$full_prefix/$cname/log/slurmdbd.log
PidFile=$full_prefix/$cname/run/slurmdbd.pid
SlurmUser=$user
StorageType=accounting_storage/mysql
StorageLoc=$SLURM_DB_NAME
StorageHost=localhost
END
if ($DB_USER ne "") {
$conf .= "StorageUser=$DB_USER\n";
}
if ($DB_PASSWD ne "") {
$conf .= "StoragePass=$DB_PASSWD\n";
}
return $conf;
}