18874: Add 'services/workbench2/' from commit 'f6f88d9ca9cdeeeebfadcfe999789bfb9f69e5c6'
[arvados.git] / tools / salt-install / common.sh
1 ##########################################################
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: CC-BY-SA-3.0
5
6 # This is generic logic used by provision.sh & installer.sh scripts
7
8 if [[ -s ${CONFIG_FILE} && -s ${CONFIG_FILE}.secrets ]]; then
9   source ${CONFIG_FILE}.secrets
10   source ${CONFIG_FILE}
11 else
12   echo >&2 "You don't seem to have a config file with initial values."
13   echo >&2 "Please create a '${CONFIG_FILE}' & '${CONFIG_FILE}.secrets' files as described in"
14   echo >&2 "  * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
15   echo >&2 "  * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
16   exit 1
17 fi
18
19 # Comma-separated list of nodes. This is used to dynamically adjust
20 # salt pillars.
21 NODELIST=""
22 for node in "${!NODES[@]}"; do
23   if [ -z "$NODELIST" ]; then
24     NODELIST="$node"
25   else
26     NODELIST="$NODELIST,$node"
27   fi
28 done
29
30 # The mapping of roles to nodes. This is used to dynamically adjust
31 # salt pillars.
32 for node in "${!NODES[@]}"; do
33   roles="${NODES[$node]}"
34
35   # Split the comma-separated roles into an array
36   IFS=',' read -ra roles_array <<< "$roles"
37
38   for role in "${roles_array[@]}"; do
39     if [ -n "${ROLE2NODES[$role]:-}" ]; then
40       ROLE2NODES["$role"]="${ROLE2NODES[$role]},$node"
41     else
42       ROLE2NODES["$role"]=$node
43     fi
44   done
45 done
46
47 # Auto-detects load-balancing mode
48 if [ -z "${ROLE2NODES['balancer']:-}" ]; then
49   ENABLE_BALANCER="no"
50 else
51   ENABLE_BALANCER="yes"
52 fi