21700: Install Bundler system-wide in Rails postinst
[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 USE_SSH_JUMPHOST=${USE_SSH_JUMPHOST:-}
20 DISABLED_CONTROLLER=""
21 DATABASE_POSTGRESQL_DEFAULT_VERSION=15
22
23 # Comma-separated list of nodes. This is used to dynamically adjust
24 # salt pillars.
25 NODELIST=""
26 for node in "${!NODES[@]}"; do
27   if [ -z "$NODELIST" ]; then
28     NODELIST="$node"
29   else
30     NODELIST="$NODELIST,$node"
31   fi
32 done
33
34 # The mapping of roles to nodes. This is used to dynamically adjust
35 # salt pillars.
36 for node in "${!NODES[@]}"; do
37   roles="${NODES[$node]}"
38
39   # Split the comma-separated roles into an array
40   IFS=',' read -ra roles_array <<< "$roles"
41
42   for role in "${roles_array[@]}"; do
43     if [ -n "${ROLE2NODES[$role]:-}" ]; then
44       ROLE2NODES["$role"]="${ROLE2NODES[$role]},$node"
45     else
46       ROLE2NODES["$role"]=$node
47     fi
48   done
49 done
50
51 # Sets TLS certificate expiration thresholds
52 TLS_EXPIRATION_YELLOW=5184000 # > 2 months
53 TLS_EXPIRATION_GREEN=15552000 # > 6 months
54 if [[ "${SSL_MODE}" == "lets-encrypt" ]]; then
55   TLS_EXPIRATION_YELLOW=1900800 # > 22 days
56   TLS_EXPIRATION_GREEN=2505600 # > 29 days
57 fi
58
59 # Auto-detects load-balancing mode
60 if [ -z "${ROLE2NODES['balancer']:-}" ]; then
61   ENABLE_BALANCER="no"
62 else
63   ENABLE_BALANCER="yes"
64 fi
65
66 # Auto-sets PG version if needed
67 if [[ -n "${ROLE2NODES['database']:-}" || "${NODELIST}" == "localhost" ]]; then
68   DATABASE_POSTGRESQL_VERSION="${DATABASE_POSTGRESQL_VERSION:-${DATABASE_POSTGRESQL_DEFAULT_VERSION}}"
69 fi