-
Notifications
You must be signed in to change notification settings - Fork 516
Expand file tree
/
Copy pathdask.sh
More file actions
686 lines (585 loc) · 20.3 KB
/
dask.sh
File metadata and controls
686 lines (585 loc) · 20.3 KB
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
#!/bin/bash
# Copyright 2020,2021,2023,2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This initialization action script will install Dask and other relevant
# libraries on a Dataproc cluster. This is supported for either "yarn" or
# "standalone" runtimes Please see dask.org and yarn.dask.org for more
# information.
set -euxo pipefail
function os_id() { grep '^ID=' /etc/os-release | cut -d= -f2 | xargs ; }
function os_version() { grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | xargs ; }
function is_ubuntu() { [[ "$(os_id)" == 'ubuntu' ]] ; }
function is_ubuntu18() { is_ubuntu && [[ "$(os_version)" == '18.04'* ]] ; }
function is_debian() { [[ "$(os_id)" == 'debian' ]] ; }
function is_debuntu() { is_debian || is_ubuntu ; }
function print_metadata_value() {
local readonly tmpfile=$(mktemp)
http_code=$(curl -f "${1}" -H "Metadata-Flavor: Google" -w "%{http_code}" \
-s -o ${tmpfile} 2>/dev/null)
local readonly return_code=$?
# If the command completed successfully, print the metadata value to stdout.
if [[ ${return_code} == 0 && ${http_code} == 200 ]]; then
cat ${tmpfile}
fi
rm -f ${tmpfile}
return ${return_code}
}
function print_metadata_value_if_exists() {
local return_code=1
local readonly url=$1
print_metadata_value ${url}
return_code=$?
return ${return_code}
}
function get_metadata_value() {
set +x
local readonly varname=$1
local -r MDS_PREFIX=http://metadata.google.internal/computeMetadata/v1
# Print the instance metadata value.
print_metadata_value_if_exists ${MDS_PREFIX}/instance/${varname}
return_code=$?
# If the instance doesn't have the value, try the project.
if [[ ${return_code} != 0 ]]; then
print_metadata_value_if_exists ${MDS_PREFIX}/project/${varname}
return_code=$?
fi
set -x
return ${return_code}
}
function get_metadata_attribute() (
set +x
local -r attribute_name="$1"
local -r default_value="${2:-}"
get_metadata_value "attributes/${attribute_name}" || echo -n "${default_value}"
)
function is_cuda12() { [[ "${CUDA_VERSION%%.*}" == "12" ]] ; }
function is_cuda11() { [[ "${CUDA_VERSION%%.*}" == "11" ]] ; }
function execute_with_retries() {
local -r cmd="$*"
for i in {0..9} ; do
if eval "$cmd"; then
return 0 ; fi
sleep 5
done
echo "Cmd '${cmd}' failed."
return 1
}
function configure_dask_yarn() {
readonly DASK_YARN_CONFIG_DIR=/etc/dask/
readonly DASK_YARN_CONFIG_FILE=${DASK_YARN_CONFIG_DIR}/config.yaml
# Minimal custom configuration is required for this
# setup. Please see https://yarn.dask.org/en/latest/quickstart.html#usage
# for information on tuning Dask-Yarn environments.
mkdir -p "${DASK_YARN_CONFIG_DIR}"
cat <<EOF >"${DASK_YARN_CONFIG_FILE}"
# Config file for Dask Yarn.
#
# These values are joined on top of the default config, found at
# https://yarn.dask.org/en/latest/configuration.html#default-configuration
yarn:
environment: python://${DASK_CONDA_ENV}/bin/python
worker:
count: 2
EOF
}
function install_systemd_dask_worker() {
echo "Installing systemd Dask Worker service..."
local -r dask_worker_local_dir="/tmp/${DASK_WORKER_SERVICE}"
mkdir -p "${dask_worker_local_dir}"
local DASK_WORKER_LAUNCHER="/usr/local/bin/${DASK_WORKER_SERVICE}-launcher.sh"
cat <<EOF >"${DASK_WORKER_LAUNCHER}"
#!/bin/bash
LOGFILE="/var/log/${DASK_WORKER_SERVICE}.log"
echo "dask worker starting, logging to \${LOGFILE}"
${DASK_CONDA_ENV}/bin/dask worker "${MASTER}:8786" --local-directory="${dask_worker_local_dir}" --memory-limit=auto >> "\${LOGFILE}" 2>&1
EOF
chmod 750 "${DASK_WORKER_LAUNCHER}"
local -r dask_service_file="/usr/lib/systemd/system/${DASK_WORKER_SERVICE}.service"
cat <<EOF >"${dask_service_file}"
[Unit]
Description=Dask Worker Service
[Service]
Type=simple
Restart=on-failure
ExecStart=/bin/bash -c 'exec ${DASK_WORKER_LAUNCHER}'
[Install]
WantedBy=multi-user.target
EOF
chmod a+r "${dask_service_file}"
systemctl daemon-reload
# Enable the service
if [[ "${ROLE}" != "Master" ]]; then
enable_worker_service="1"
else
local RUN_WORKER_ON_MASTER="$(get_metadata_attribute dask-worker-on-master 'true')"
# Enable service on single-node cluster (no workers)
local worker_count="$(get_metadata_attribute dataproc-worker-count)"
if [[ "${worker_count}" == "0" || "${RUN_WORKER_ON_MASTER}" == "true" ]]; then
enable_worker_service="1"
fi
fi
if [[ "${enable_worker_service}" == "1" ]]; then
systemctl enable "${DASK_WORKER_SERVICE}"
systemctl restart "${DASK_WORKER_SERVICE}"
fi
}
function install_systemd_dask_scheduler() {
# only run scheduler on primary master
if [[ "$(hostname -s)" != "${MASTER}" ]]; then return ; fi
echo "Installing systemd Dask Scheduler service..."
local -r dask_scheduler_local_dir="/tmp/${DASK_SCHEDULER_SERVICE}"
mkdir -p "${dask_scheduler_local_dir}"
local DASK_SCHEDULER_LAUNCHER="/usr/local/bin/${DASK_SCHEDULER_SERVICE}-launcher.sh"
cat <<EOF >"${DASK_SCHEDULER_LAUNCHER}"
#!/bin/bash
LOGFILE="/var/log/${DASK_SCHEDULER_SERVICE}.log"
echo "dask scheduler starting, logging to \${LOGFILE}"
${DASK_CONDA_ENV}/bin/dask scheduler >> "\${LOGFILE}" 2>&1
EOF
chmod 750 "${DASK_SCHEDULER_LAUNCHER}"
local -r dask_service_file="/usr/lib/systemd/system/${DASK_SCHEDULER_SERVICE}.service"
cat <<EOF >"${dask_service_file}"
[Unit]
Description=Dask Scheduler Service
[Service]
Type=simple
Restart=on-failure
ExecStart=/bin/bash -c 'exec ${DASK_SCHEDULER_LAUNCHER}'
[Install]
WantedBy=multi-user.target
EOF
chmod a+r "${dask_service_file}"
systemctl daemon-reload
# Enable the service
systemctl enable "${DASK_SCHEDULER_SERVICE}"
}
function install_systemd_dask_service() {
install_systemd_dask_scheduler
install_systemd_dask_worker
}
function restart_knox() {
systemctl stop knox
rm -rf "${KNOX_HOME}/data/deployments/*"
systemctl start knox
}
function configure_knox_for_dask() {
if [[ ! -d "${KNOX_HOME}" ]]; then
echo "Skip configuring Knox rules for Dask"
return 0
fi
local DASK_UI_PORT=8787
if [[ -f /etc/knox/conf/topologies/default.xml ]]; then
sed -i \
"/<\/topology>/i <service><role>DASK<\/role><url>http://localhost:${DASK_UI_PORT}<\/url><\/service> <service><role>DASKWS<\/role><url>ws:\/\/${MASTER}:${DASK_UI_PORT}<\/url><\/service>" \
/etc/knox/conf/topologies/default.xml
fi
mkdir -p "${KNOX_DASK_DIR}"
cat >"${KNOX_DASK_DIR}/service.xml" <<'EOF'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<service role="DASK" name="dask" version="0.1.0">
<policies>
<policy role="webappsec"/>
<policy role="authentication" name="Anonymous"/>
<policy role="rewrite"/>
<policy role="authorization"/>
</policies>
<routes>
<!-- Javascript paths -->
<route path="/dask/**/*.js">
<rewrite apply="DASK/dask/inbound/js/dask" to="request.url"/>
<rewrite apply="DASK/dask/outbound/js" to="response.body"/>
</route>
<route path="/dask/**/*.js?**">
<rewrite apply="DASK/dask/inbound/js/dask" to="request.url"/>
<rewrite apply="DASK/dask/outbound/js" to="response.body"/>
</route>
<!-- CSS paths -->
<route path="/dask/**/*.css">
<rewrite apply="DASK/dask/inbound/css/dask" to="request.url"/>
</route>
<!-- General path routing -->
<route path="/dask">
<rewrite apply="DASK/dask/inbound/root" to="request.url"/>
<rewrite apply="DASK/dask/outbound/headers" to="response.headers"/>
</route>
<route path="/dask/**">
<rewrite apply="DASK/dask/inbound/root/path" to="request.url"/>
<rewrite apply="DASK/dask/outbound/headers" to="response.headers"/>
<rewrite apply="DASK/dask/outbound/logs" to="response.body"/>
</route>
<route path="/dask/**?**">
<rewrite apply="DASK/dask/inbound/root/query" to="request.url"/>
<rewrite apply="DASK/dask/outbound/headers" to="response.headers"/>
<rewrite apply="DASK/dask/outbound/logs" to="response.body"/>
</route>
</routes>
<dispatch classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoChunkedPostDispatch"/>
</service>
EOF
cat >"${KNOX_DASK_DIR}/rewrite.xml" <<'EOF'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rules>
<rule dir="IN" name="DASK/dask/inbound/js/dask" pattern="http://*:*/**/dask/{**}?{**}">
<rewrite template="{$serviceUrl[DASK]}/{**}?{**}"/>
</rule>
<rule dir="IN" name="DASK/dask/inbound/root" pattern="http://*:*/**/dask">
<rewrite template="{$serviceUrl[DASK]}"/>
</rule>
<rule dir="IN" name="DASK/dask/inbound/root/path" pattern="http://*:*/**/dask/{**}">
<rewrite template="{$serviceUrl[DASK]}/{**}"/>
</rule>
<rule dir="IN" name="DASK/dask/inbound/root/query" pattern="http://*:*/**/dask/{**}?{**}">
<rewrite template="{$serviceUrl[DASK]}/{**}?{**}"/>
</rule>
<rule dir="IN" name="DASK/dask/inbound/css/dask" pattern="http://*:*/**/dask/{**}?{**}">
<rewrite template="{$serviceUrl[DASK]}/{**}?{**}"/>
</rule>
<!-- without the /gateway/default prefix -->
<rule dir="IN" name="DASK/dask/inbound/root/noprefix" pattern="http://*:*/dask">
<rewrite template="{$serviceUrl[DASK]}"/>
</rule>
<rule dir="OUT" name="DASK/dask/outbound/logs" pattern="/logs">
<rewrite template="{$frontend[path]}/dask/info/logs"/>
</rule>
<!-- Rewrite redirect responses Location header -->
<filter name="DASK/dask/outbound/headers">
<content type="application/x-http-headers">
<apply path="Location" rule="DASK/dask/outbound/headers/location"/>
</content>
</filter>
<rule dir="OUT" name="DASK/dask/outbound/headers/location" flow="OR">
<match pattern="*://*:*/">
<rewrite template="{$frontend[path]}/dask/"/>
</match>
<match pattern="*://*:*/{**}">
<rewrite template="{$frontend[path]}/dask/{**}"/>
</match>
<match pattern="*://*:*/{**}?{**}">
<rewrite template="{$frontend[path]}/dask/{**}?{**}"/>
</match>
<match pattern="/{**}">
<rewrite template="{$frontend[path]}/dask/{**}"/>
</match>
<match pattern="/{**}?{**}">
<rewrite template="{$frontend[path]}/dask/{**}?{**}"/>
</match>
</rule>
</rules>
EOF
mkdir -p "${KNOX_DASKWS_DIR}"
cat >"${KNOX_DASKWS_DIR}/service.xml" <<'EOF'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<service role="DASKWS" name="daskws" version="0.1.0">
<policies>
<policy role="webappsec"/>
<policy role="authentication" name="Anonymous"/>
<policy role="rewrite"/>
<policy role="authorization"/>
</policies>
<routes>
<route path="/dask/**/ws">
<rewrite apply="DASKWS/daskws/inbound/ws" to="request.url"/>
</route>
</routes>
<dispatch classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoChunkedPostDispatch"/>
</service>
EOF
cat >"${KNOX_DASKWS_DIR}/rewrite.xml" <<'EOF'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rules>
<rule dir="IN" name="DASKWS/daskws/inbound/ws" pattern="ws://*:*/**/dask/{**}/ws">
<rewrite template="{$serviceUrl[DASKWS]}/{**}/ws"/>
</rule>
</rules>
EOF
chown -R knox:knox "${KNOX_DASK_DIR}" "${KNOX_DASKWS_DIR}"
# Do not restart knox during pre-init script run
if [[ -n "${ROLE}" ]]; then
restart_knox
fi
}
function configure_fluentd_for_dask() {
if [[ "$(hostname -s)" == "${MASTER}" ]]; then
cat >/etc/google-fluentd/config.d/dataproc-dask.conf <<EOF
# Fluentd config for Dask logs
# Dask scheduler
<source>
@type tail
path /var/log/dask-scheduler.log
pos_file /var/tmp/fluentd.dataproc.dask.scheduler.pos
read_from_head true
tag google.dataproc.dask-scheduler
<parse>
@type none
</parse>
</source>
<filter google.dataproc.dask-scheduler>
@type record_transformer
<record>
filename dask-scheduler.log
</record>
</filter>
EOF
fi
if [[ "${enable_worker_service}" == "1" ]]; then
cat >>/etc/google-fluentd/config.d/dataproc-dask.conf <<EOF
# Dask worker
<source>
@type tail
path /var/log/dask-worker.log
pos_file /var/tmp/fluentd.dataproc.dask.worker.pos
read_from_head true
tag google.dataproc.dask-worker
<parse>
@type none
</parse>
</source>
<filter google.dataproc.dask-worker>
@type record_transformer
<record>
filename dask-worker.log
</record>
</filter>
EOF
fi
systemctl restart google-fluentd
}
function install_dask() {
if is_cuda12 ; then
local python_spec="python>=3.11"
local cuda_spec="cuda-version>=12,<13"
local dask_spec="dask>=2024.7"
elif is_cuda11 ; then
local python_spec="python>=3.9"
local cuda_spec="cuda-version>=11,<12.0a0"
local dask_spec="dask"
fi
CONDA_PACKAGES=()
if [[ "${DASK_RUNTIME}" == 'yarn' ]]; then
# Pin `distributed` and `dask` package versions to old release
# because `dask-yarn` 0.9 uses skein in a way which
# is not compatible with `distributed` package 2022.2 and newer:
# https://github.com/dask/dask-yarn/issues/155
dask_spec="dask<2022.2"
python_spec="python>=3.7,<3.8.0a0"
if is_ubuntu18 ; then
# the libuuid.so.1 distributed with fiona 1.8.22 dumps core when calling uuid_generate_time_generic
CONDA_PACKAGES+=("fiona<1.8.22")
fi
CONDA_PACKAGES+=('dask-yarn=0.9' "distributed<2022.2")
fi
CONDA_PACKAGES+=(
"${cuda_spec}"
"${dask_spec}"
"dask-bigquery"
"dask-ml"
"dask-sql"
)
# Install dask
mamba="/opt/conda/miniconda3/bin/mamba"
conda="/opt/conda/miniconda3/bin/conda"
( set +e
local is_installed=0
for installer in "${mamba}" "${conda}" ; do
test -d "${DASK_CONDA_ENV}" || \
time "${installer}" "create" -m -n "dask" -y --no-channel-priority \
-c 'conda-forge' -c 'nvidia' \
${CONDA_PACKAGES[*]} \
"${python_spec}" \
> "${install_log}" 2>&1 && retval=$? || { retval=$? ; cat "${install_log}" ; }
sync
if [[ "$retval" == "0" ]] ; then
is_installed="1"
break
fi
"${conda}" config --set channel_priority flexible
done
if [[ "${is_installed}" == "0" ]]; then
echo "failed to install dask"
return 1
fi
)
}
function main() {
# Install Dask
install_dask
# In "standalone" mode, Dask relies on a systemd unit to launch.
# In "yarn" mode, it relies a config.yaml file.
if [[ "${DASK_RUNTIME}" == "yarn" ]]; then
# Create Dask YARN config file
configure_dask_yarn
elif [[ "${DASK_RUNTIME}" == "standalone" ]]; then
# Create Dask service
install_systemd_dask_service
if [[ "$(hostname -s)" == "${MASTER}" ]]; then
systemctl start "${DASK_SCHEDULER_SERVICE}"
systemctl status "${DASK_SCHEDULER_SERVICE}"
fi
echo "Starting Dask 'standalone' cluster..."
if [[ "${enable_worker_service}" == "1" ]]; then
systemctl start "${DASK_WORKER_SERVICE}"
systemctl status "${DASK_WORKER_SERVICE}"
fi
configure_knox_for_dask
local DASK_CLOUD_LOGGING="$(get_metadata_attribute dask-cloud-logging || echo 'false')"
if [[ "${DASK_CLOUD_LOGGING}" == "true" ]]; then
configure_fluentd_for_dask
fi
else
echo "Unsupported Dask Runtime: ${DASK_RUNTIME}"
exit 1
fi
echo "Dask for ${DASK_RUNTIME} successfully initialized."
}
function exit_handler() {
set +ex
echo "Exit handler invoked"
# Free conda cache
/opt/conda/miniconda3/bin/conda clean -a > /dev/null 2>&1
# Clear pip cache
pip cache purge || echo "unable to purge pip cache"
# If system memory was sufficient to mount memory-backed filesystems
if [[ "${tmpdir}" == "/mnt/shm" ]] ; then
# Stop hadoop services
systemctl list-units | perl -n -e 'qx(systemctl stop $1) if /^.*? ((hadoop|knox|hive|mapred|yarn|hdfs)\S*).service/'
# remove the tmpfs conda pkgs_dirs
/opt/conda/miniconda3/bin/conda config --remove pkgs_dirs /mnt/shm || echo "unable to remove pkgs_dirs conda config"
# remove the tmpfs pip cache-dir
pip config unset global.cache-dir || echo "unable to unset global pip cache"
# Clean up shared memory mounts
for shmdir in /var/cache/apt/archives /var/cache/dnf /mnt/shm ; do
if grep -q "^tmpfs ${shmdir}" /proc/mounts ; then
sync
sleep 3s
execute_with_retries umount -f ${shmdir}
fi
done
umount -f /tmp
systemctl list-units | perl -n -e 'qx(systemctl start $1) if /^.*? ((hadoop|knox|hive|mapred|yarn|hdfs)\S*).service/'
fi
# Clean up OS package cache ; re-hold systemd package
if is_debuntu ; then
apt-get -y -qq clean
apt-get -y -qq autoremove
else
dnf clean all
fi
# print disk usage statistics for large components
if is_ubuntu ; then
du -hs \
/usr/lib/{pig,hive,hadoop,jvm,spark,google-cloud-sdk,x86_64-linux-gnu} \
/usr/lib \
/opt/nvidia/* \
/usr/local/cuda-1?.? \
/opt/conda/miniconda3 \
"${DASK_CONDA_ENV}"
elif is_debian ; then
du -hs \
/usr/lib/{pig,hive,hadoop,jvm,spark,google-cloud-sdk,x86_64-linux-gnu} \
/usr/lib \
/usr/local/cuda-1?.? \
/opt/conda/miniconda3 \
"${DASK_CONDA_ENV}"
else
du -hs \
/var/lib/docker \
/usr/lib/{pig,hive,hadoop,firmware,jvm,spark,atlas} \
/usr/lib64/google-cloud-sdk \
/usr/lib \
/opt/nvidia/* \
/usr/local/cuda-1?.? \
/opt/conda/miniconda3 \
"${DASK_CONDA_ENV}"
fi
# Process disk usage logs from installation period
rm -f /run/keep-running-df
sync
sleep 5.01s
# compute maximum size of disk during installation
# Log file contains logs like the following (minus the preceeding #):
#Filesystem 1K-blocks Used Available Use% Mounted on
#/dev/vda2 7096908 2611344 4182932 39% /
df / | tee -a "/run/disk-usage.log"
perl -e '@siz=( sort { $a => $b }
map { (split)[2] =~ /^(\d+)/ }
grep { m:^/: } <STDIN> );
$max=$siz[0]; $min=$siz[-1]; $inc=$max-$min;
print( " samples-taken: ", scalar @siz, $/,
"maximum-disk-used: $max", $/,
"minimum-disk-used: $min", $/,
" increased-by: $inc", $/ )' < "/run/disk-usage.log"
echo "exit_handler has completed"
# zero free disk space
if [[ -n "$(get_metadata_attribute creating-image)" ]]; then
dd if=/dev/zero of=/zero
sync
sleep 3s
rm -f /zero
fi
return 0
}
function prepare_to_install() {
readonly DEFAULT_CUDA_VERSION="12.4"
CUDA_VERSION=$(get_metadata_attribute 'cuda-version' ${DEFAULT_CUDA_VERSION})
readonly CUDA_VERSION
readonly ROLE=$(get_metadata_attribute dataproc-role)
readonly MASTER=$(get_metadata_attribute dataproc-master)
# Dask config
DASK_RUNTIME="$(get_metadata_attribute dask-runtime || echo 'standalone')"
readonly DASK_RUNTIME
readonly DASK_SERVICE=dask-cluster
readonly DASK_WORKER_SERVICE=dask-worker
readonly DASK_SCHEDULER_SERVICE=dask-scheduler
readonly DASK_CONDA_ENV="/opt/conda/miniconda3/envs/dask"
# Knox config
readonly KNOX_HOME=/usr/lib/knox
readonly KNOX_DASK_DIR="${KNOX_HOME}/data/services/dask/0.1.0"
readonly KNOX_DASKWS_DIR="${KNOX_HOME}/data/services/daskws/0.1.0"
enable_worker_service="0"
free_mem="$(awk '/^MemFree/ {print $2}' /proc/meminfo)"
# Write to a ramdisk instead of churning the persistent disk
if [[ ${free_mem} -ge 10500000 ]]; then
tmpdir=/mnt/shm
mkdir -p /mnt/shm
mount -t tmpfs tmpfs /mnt/shm
# Download conda packages to tmpfs
/opt/conda/miniconda3/bin/conda config --add pkgs_dirs /mnt/shm
mount -t tmpfs tmpfs /mnt/shm
# Download pip packages to tmpfs
pip config set global.cache-dir /mnt/shm || echo "unable to set global.cache-dir"
# Download OS packages to tmpfs
if is_debuntu ; then
mount -t tmpfs tmpfs /var/cache/apt/archives
else
while [[ -f /var/cache/dnf/metadata_lock.pid ]] ; do sleep 1s ; done
mount -t tmpfs tmpfs /var/cache/dnf
fi
else
tmpdir=/tmp
fi
install_log="/run/install.log"
trap exit_handler EXIT
# Monitor disk usage in a screen session
if is_debuntu ; then
apt-get install -y -qq screen
else
dnf -y -q install screen
fi
df / | tee "/run/disk-usage.log"
touch "/run/keep-running-df"
screen -d -m -US keep-running-df \
bash -c "while [[ -f /run/keep-running-df ]] ; do df / | tee -a /run/disk-usage.log ; sleep 5s ; done"
}
prepare_to_install
main