-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path95_setup-clustermanagement-program.sh
More file actions
61 lines (49 loc) · 2.62 KB
/
95_setup-clustermanagement-program.sh
File metadata and controls
61 lines (49 loc) · 2.62 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
#!/usr/bin/env bash
# Copyright 2024-2026 The MathWorks, Inc.
PS4='+ [\d \t] '
set -x
# Initialize cluster management data file.
termination_policy="${TERMINATION_POLICY}"
# Determine termination policy
if [[ "${TERMINATION_POLICY}" == "When cluster is idle" ]]; then
termination_policy="on_idle"
elif [[ ! "${TERMINATION_POLICY}" =~ ^After\ [0-9]+\ hour[s]?$ ]]; then
termination_policy="never"
fi
# Set auto_termination_flag based on user's choice
auto_termination_flag=$([[ "${TERMINATION_POLICY}" != 'Disable auto-termination' ]] && echo "true" || echo "false")
# This boolean flag tells the clustermanagement program to use private IPs of the workers instead of hostnames
use_private_ip_mapping=$([[ "${COMMUNICATION_MODE}" == "PrivateIP" ]] && echo "true" || echo "false")
# Check if the current node is the HEADNODE
if [[ ${NODE_TYPE} == 'HEADNODE' ]]; then
# Update the cluster management data file with the appropriate settings.
jq --arg desired_cap "${DESIRED_CAPACITY}" \
--arg policy "$termination_policy" \
--arg mjs_status_log_file "${MJS_STATUS_LOG_FILE}" \
--arg dns_search_suffix "${DNS_SEARCH_SUFFIX}" \
--argjson auto_termination_flag $auto_termination_flag \
--argjson use_private_ip_mapping $use_private_ip_mapping \
'.config.initial_desired_capacity=$desired_cap |
.state.last_termination_policy=$policy |
.config.initial_termination_policy=$policy |
.config.mjs_status_log_file=$mjs_status_log_file |
.config.autotermination_enabled=$auto_termination_flag |
.config.dns_search_suffix=$dns_search_suffix |
.config.use_private_ip_mapping=$use_private_ip_mapping' \
${CLUSTER_MANAGEMENT_DATA_FILE} > tmp.$$.json && mv tmp.$$.json ${CLUSTER_MANAGEMENT_DATA_FILE}
# Set up MJS Cluster for Auto-Resizing
# Reference: https://www.mathworks.com/help/matlab-parallel-server/set-up-your-mjs-cluster-for-resizing.html
# Determine autoscaling_flag based on ENABLE_AUTOSCALING and MATLAB_RELEASE
autoscaling_flag='false'
if [[ ${ENABLE_AUTOSCALING} == 'Yes' ]] && [[ "${MATLAB_RELEASE}" > 'R2021b' ]]; then
autoscaling_flag='true'
elif [[ ${ENABLE_AUTOSCALING} == 'Yes' ]]; then
echo 'WARNING: Auto-Resizing is only available for R2022a and later.'
fi
# Apply the autoscaling setting to the cluster management data file.
jq --argjson flag "$autoscaling_flag" \
'.config.autoscaling_enabled=$flag' \
${CLUSTER_MANAGEMENT_DATA_FILE} > temp.json && mv temp.json ${CLUSTER_MANAGEMENT_DATA_FILE}
systemctl enable clustermanagement.timer
systemctl start clustermanagement.timer
fi