3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: CC-BY-SA-3.0
7 # If you want to test arvados in a single host, you can run this script, which
8 # will install it using salt masterless
9 # This script is run by the Vagrant file when you run it with
15 # capture the directory that the script is running from
16 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
20 echo >&2 "Usage: ${0} [-h] [-h]"
22 echo >&2 "${0} options:"
23 echo >&2 " -d, --debug Run salt installation in debug mode"
24 echo >&2 " -c <local.params>, --config <local.params> Path to the local.params config file"
25 echo >&2 " -t, --test Test installation running a CWL workflow"
26 echo >&2 " -r, --roles List of Arvados roles to apply to the host, comma separated"
27 echo >&2 " Possible values are:"
30 echo >&2 " controller"
31 echo >&2 " dispatcher"
33 echo >&2 " keepbalance"
36 echo >&2 " monitoring"
41 echo >&2 " workbench2"
42 echo >&2 " Defaults to applying them all"
43 echo >&2 " -h, --help Display this help and exit"
44 echo >&2 " --dump-config <dest_dir> Dumps the pillars and states to a directory"
45 echo >&2 " This parameter does not perform any installation at all. It's"
46 echo >&2 " intended to give you a parsed set of configuration files so"
47 echo >&2 " you can inspect them or use them in you Saltstack infrastructure."
49 echo >&2 " - parses the pillar and states templates,"
50 echo >&2 " - downloads the helper formulas with their desired versions,"
51 echo >&2 " - prepares the 'top.sls' files both for pillars and states"
52 echo >&2 " for the selected role(s)"
53 echo >&2 " - writes the resulting files into <dest_dir>"
54 echo >&2 " -v, --vagrant Run in vagrant and use the /vagrant shared dir"
55 echo >&2 " --development Run in dev mode, using snakeoil certs"
60 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
61 if ! which getopt > /dev/null; then
62 echo >&2 "GNU getopt is required to run this script. Please install it and re-reun it"
66 TEMP=$(getopt -o c:dhp:r:tv \
67 --long config:,debug,development,dump-config:,help,roles:,test,vagrant \
71 then echo "Please check the parameters you entered and re-run again"
74 # Note the quotes around `$TEMP': they are essential!
77 while [ ${#} -ge 1 ]; do
89 if [[ ${2} = /* ]]; then
90 DUMP_SALT_CONFIG_DIR=${2}
92 DUMP_SALT_CONFIG_DIR=${PWD}/${2}
95 S_DIR="${DUMP_SALT_CONFIG_DIR}/salt"
97 F_DIR="${DUMP_SALT_CONFIG_DIR}/formulas"
99 P_DIR="${DUMP_SALT_CONFIG_DIR}/pillars"
101 T_DIR="${DUMP_SALT_CONFIG_DIR}/tests"
112 # Verify the role exists
113 if [[ ! "database,api,balancer,controller,keepstore,websocket,keepweb,workbench2,webshell,keepbalance,keepproxy,shell,workbench,dispatcher,monitoring" == *"$i"* ]]; then
114 echo "The role '${i}' is not a valid role"
118 ROLES="${ROLES} ${i}"
146 mkdir -p --mode=0700 /srv/salt/certs
148 if [ -f ${cert_dir}/${cert_name}.crt ]; then
149 install --mode=0600 ${cert_dir}/${cert_name}.crt /srv/salt/certs/arvados-${cert_name}.pem
151 echo "${cert_dir}/${cert_name}.crt does not exist. Exiting"
154 if [ -f ${cert_dir}/${cert_name}.key ]; then
155 install --mode=0600 ${cert_dir}/${cert_name}.key /srv/salt/certs/arvados-${cert_name}.key
157 echo "${cert_dir}/${cert_name}.key does not exist. Exiting"
163 CONFIG_FILE="${SCRIPT_DIR}/local.params"
164 CONFIG_DIR="local_config_dir"
167 CONTROLLER_EXT_SSL_PORT=443
170 NGINX_INSTALL_SOURCE="install_from_repo"
175 # Hostnames/IPs used for single-host deploys
180 INITIAL_USER_EMAIL=""
181 INITIAL_USER_PASSWORD=""
183 CONTROLLER_EXT_SSL_PORT=8000
184 KEEP_EXT_SSL_PORT=25101
185 # Both for collections and downloads
186 KEEPWEB_EXT_SSL_PORT=9002
187 WEBSHELL_EXT_SSL_PORT=4202
188 WEBSOCKET_EXT_SSL_PORT=8002
189 WORKBENCH1_EXT_SSL_PORT=443
190 WORKBENCH2_EXT_SSL_PORT=3001
192 SSL_MODE="self-signed"
193 USE_LETSENCRYPT_ROUTE53="no"
194 CUSTOM_CERTS_DIR="${SCRIPT_DIR}/local_config_dir/certs"
196 GRAFANA_DASHBOARDS_DIR="${SCRIPT_DIR}/local_config_dir/dashboards"
198 ## These are ARVADOS-related parameters
199 # For a stable release, change RELEASE "production" and VERSION to the
200 # package version (including the iteration, e.g. X.Y.Z-1) of the
202 # The "local.params.example.*" files already set "RELEASE=production"
203 # to deploy production-ready packages
204 RELEASE="development"
207 # These are arvados-formula-related parameters
208 # An arvados-formula tag. For a stable release, this should be a
209 # branch name (e.g. X.Y-dev) or tag for the release.
210 # ARVADOS_TAG="2.2.0"
213 # We pin the salt version to avoid potential incompatibilities when a new
214 # stable version is released.
217 # Other formula versions we depend on
218 #POSTGRES_TAG="v0.44.0"
219 #POSTGRES_URL="https://github.com/saltstack-formulas/postgres-formula.git"
220 POSTGRES_TAG="0.45.0-bugfix327"
221 POSTGRES_URL="https://github.com/arvados/postgres-formula.git"
225 LETSENCRYPT_TAG="v2.1.0"
226 LOGROTATE_TAG="v0.14.0"
227 PROMETHEUS_TAG="v5.6.5"
231 DUMP_SALT_CONFIG_DIR=""
235 F_DIR="/srv/formulas"
239 T_DIR="/tmp/cluster_tests"
249 if [ ! -d ${CONFIG_DIR} ]; then
250 echo >&2 "You don't seem to have a config directory with pillars and states."
251 echo >&2 "Please create a '${CONFIG_DIR}' directory (as configured in your '${CONFIG_FILE}'). Please see"
252 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
253 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
257 if grep -rni 'fixme' ${CONFIG_FILE}.secrets ${CONFIG_FILE} ${CONFIG_DIR} ; then
258 echo >&2 "The config files has some parameters that need to be modified."
259 echo >&2 "Please, fix them and re-run the provision script."
263 if ! grep -qE '^[[:alnum:]]{5}$' <<<${CLUSTER} ; then
264 echo >&2 "ERROR: <CLUSTER> must be exactly 5 lowercase alphanumeric characters long"
265 echo >&2 "Fix the cluster name in the 'local.params' file and re-run the provision script"
269 # Only used in single_host/single_name deploys
270 if [ ! -z "${HOSTNAME_EXT}" ] ; then
271 # We need to add some extra control vars to manage a single certificate vs. multiple
272 USE_SINGLE_HOSTNAME="yes"
273 # Make sure that the value configured as IP_INT is a real IP on the system.
274 # If we don't error out early here when there is a mismatch, the formula will
275 # fail with hard to interpret nginx errors later on.
276 ip addr list |grep "${IP_INT}/" >/dev/null
277 if [[ $? -ne 0 ]]; then
278 echo "Unable to find the IP_INT address '${IP_INT}' on the system, please correct the value in local.params. Exiting..."
282 USE_SINGLE_HOSTNAME="no"
283 # We set this variable, anyway, so sed lines do not fail and we don't need to add more
285 HOSTNAME_EXT="${DOMAIN}"
288 if [ "${DUMP_CONFIG}" = "yes" ]; then
289 echo "The provision installer will just dump a config under ${DUMP_SALT_CONFIG_DIR} and exit"
291 # Install a few dependency packages
292 # First, let's figure out the OS we're working on
293 OS_ID=$(grep ^ID= /etc/os-release |cut -f 2 -d= |cut -f 2 -d \")
294 echo "Detected distro: ${OS_ID}"
298 echo "WARNING! Disabling SELinux, see https://dev.arvados.org/issues/18019"
299 sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
300 setenforce permissive
301 yum install -y curl git jq
304 # Wait 2 minutes for any apt locks to clear
305 # This option is supported from apt 1.9.1 and ignored in older apt versions.
306 # Cf. https://blog.sinjakli.co.uk/2021/10/25/waiting-for-apt-locks-without-the-hacky-bash-scripts/
307 DEBIAN_FRONTEND=noninteractive apt -o DPkg::Lock::Timeout=120 update
308 DEBIAN_FRONTEND=noninteractive apt install -y curl git jq
312 if which salt-call; then
313 echo "Salt already installed"
315 curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
316 sh /tmp/bootstrap_salt.sh -XdfP -x python3 old-stable ${SALT_VERSION}
317 /bin/systemctl stop salt-minion.service
318 /bin/systemctl disable salt-minion.service
321 # Set salt to masterless mode
322 cat > /etc/salt/minion << EOFSM
337 mkdir -p ${S_DIR} ${F_DIR} ${P_DIR} ${T_DIR}
339 # Get the formula and dependencies
340 cd ${F_DIR} || exit 1
341 echo "Cloning formulas"
342 test -d docker && ( cd docker && git fetch ) \
343 || git clone --quiet https://github.com/saltstack-formulas/docker-formula.git ${F_DIR}/docker
344 ( cd docker && git checkout --quiet tags/"${DOCKER_TAG}" )
347 test -d locale && ( cd locale && git fetch ) \
348 || git clone --quiet https://github.com/saltstack-formulas/locale-formula.git ${F_DIR}/locale
349 ( cd locale && git checkout --quiet tags/"${LOCALE_TAG}" )
352 test -d nginx && ( cd nginx && git fetch ) \
353 || git clone --quiet https://github.com/saltstack-formulas/nginx-formula.git ${F_DIR}/nginx
354 ( cd nginx && git checkout --quiet tags/"${NGINX_TAG}" )
357 test -d postgres && ( cd postgres && git fetch ) \
358 || git clone --quiet ${POSTGRES_URL} ${F_DIR}/postgres
359 ( cd postgres && git checkout --quiet tags/"${POSTGRES_TAG}" )
362 test -d prometheus && ( cd prometheus && git fetch ) \
363 || git clone --quiet https://github.com/saltstack-formulas/prometheus-formula.git ${F_DIR}/prometheus
364 ( cd prometheus && git checkout --quiet tags/"${PROMETHEUS_TAG}" )
367 test -d grafana && ( cd grafana && git fetch ) \
368 || git clone --quiet https://github.com/saltstack-formulas/grafana-formula.git ${F_DIR}/grafana
369 ( cd grafana && git checkout --quiet "${GRAFANA_TAG}" )
371 echo "...letsencrypt"
372 test -d letsencrypt && ( cd letsencrypt && git fetch ) \
373 || git clone --quiet https://github.com/saltstack-formulas/letsencrypt-formula.git ${F_DIR}/letsencrypt
374 ( cd letsencrypt && git checkout --quiet tags/"${LETSENCRYPT_TAG}" )
377 test -d logrotate && ( cd logrotate && git fetch ) \
378 || git clone --quiet https://github.com/saltstack-formulas/logrotate-formula.git ${F_DIR}/logrotate
379 ( cd logrotate && git checkout --quiet tags/"${LOGROTATE_TAG}" )
382 test -d arvados || git clone --quiet https://git.arvados.org/arvados-formula.git ${F_DIR}/arvados
384 # If we want to try a specific branch of the formula
385 if [ "x${BRANCH}" != "x" ]; then
386 ( cd ${F_DIR}/arvados && git checkout --quiet -t origin/"${BRANCH}" -b "${BRANCH}" )
387 elif [ "x${ARVADOS_TAG}" != "x" ]; then
388 ( cd ${F_DIR}/arvados && git checkout --quiet tags/"${ARVADOS_TAG}" -b "${ARVADOS_TAG}" )
391 if [ "x${VAGRANT}" = "xyes" ]; then
392 EXTRA_STATES_DIR="/home/vagrant/${CONFIG_DIR}/states"
393 SOURCE_PILLARS_DIR="/home/vagrant/${CONFIG_DIR}/pillars"
394 SOURCE_TOFS_DIR="/home/vagrant/${CONFIG_DIR}/tofs"
395 SOURCE_TESTS_DIR="/home/vagrant/${TESTS_DIR}"
397 EXTRA_STATES_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/states"
398 SOURCE_PILLARS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/pillars"
399 SOURCE_TOFS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/tofs"
400 SOURCE_TESTS_DIR="${SCRIPT_DIR}/${TESTS_DIR}"
403 SOURCE_STATES_DIR="${EXTRA_STATES_DIR}"
405 echo "Writing pillars and states"
407 # Replace variables (cluster, domain, etc) in the pillars, states and tests
408 # to ease deployment for newcomers
409 if [ ! -d "${SOURCE_PILLARS_DIR}" ]; then
410 echo "${SOURCE_PILLARS_DIR} does not exist or is not a directory. Exiting."
413 for f in $(ls "${SOURCE_PILLARS_DIR}"/*); do
414 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
415 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
416 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
417 s#__CLUSTER__#${CLUSTER}#g;
418 s#__DOMAIN__#${DOMAIN}#g;
419 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
420 s#__IP_INT__#${IP_INT}#g;
421 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
422 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
423 s#__INITIAL_USER__#${INITIAL_USER}#g;
424 s#__LE_AWS_REGION__#${LE_AWS_REGION}#g;
425 s#__LE_AWS_SECRET_ACCESS_KEY__#${LE_AWS_SECRET_ACCESS_KEY}#g;
426 s#__LE_AWS_ACCESS_KEY_ID__#${LE_AWS_ACCESS_KEY_ID}#g;
427 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
428 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
429 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
430 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
431 s#__RELEASE__#${RELEASE}#g;
432 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
433 s#__VERSION__#${VERSION}#g;
434 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
435 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
436 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
437 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
438 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
439 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
440 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
441 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
442 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
443 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
444 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
445 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
446 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
447 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
448 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
449 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g;
450 s#__SSL_KEY_ENCRYPTED__#${SSL_KEY_ENCRYPTED}#g;
451 s#__SSL_KEY_AWS_REGION__#${SSL_KEY_AWS_REGION}#g;
452 s#__SSL_KEY_AWS_SECRET_NAME__#${SSL_KEY_AWS_SECRET_NAME}#g;
453 s#__CONTROLLER_NGINX_WORKERS__#${CONTROLLER_NGINX_WORKERS}#g;
454 s#__CONTROLLER_MAX_CONCURRENT_REQUESTS__#${CONTROLLER_MAX_CONCURRENT_REQUESTS}#g;
455 s#__MONITORING_USERNAME__#${MONITORING_USERNAME}#g;
456 s#__MONITORING_EMAIL__#${MONITORING_EMAIL}#g;
457 s#__MONITORING_PASSWORD__#${MONITORING_PASSWORD}#g;
458 s#__DISPATCHER_SSH_PRIVKEY__#${DISPATCHER_SSH_PRIVKEY//$'\n'/\\n}#g;
459 s#__ENABLE_BALANCER__#${ENABLE_BALANCER}#g;
460 s#__DISABLED_CONTROLLER__#${DISABLED_CONTROLLER}#g;
461 s#__BALANCER_NODENAME__#${ROLES['balancer']}#g;
462 s#__PROMETHEUS_NODENAME__#${ROLES['monitoring']}#g;
463 s#__CONTROLLER_NODES__#${ROLES['controller']}#g;
464 s#__NODELIST__#${NODELIST}#g;
465 s#__DISPATCHER_INT_IP__#${DISPATCHER_INT_IP}#g;
466 s#__KEEPBALANCE_INT_IP__#${KEEPBALANCE_INT_IP}#g;
467 s#__COMPUTE_AMI__#${COMPUTE_AMI}#g;
468 s#__COMPUTE_SG__#${COMPUTE_SG}#g;
469 s#__COMPUTE_SUBNET__#${COMPUTE_SUBNET}#g;
470 s#__COMPUTE_AWS_REGION__#${COMPUTE_AWS_REGION}#g;
471 s#__COMPUTE_USER__#${COMPUTE_USER}#g;
472 s#__KEEP_AWS_REGION__#${KEEP_AWS_REGION}#g" \
473 "${f}" > "${P_DIR}"/$(basename "${f}")
476 if [ ! -d "${SOURCE_TESTS_DIR}" ]; then
477 echo "WARNING: The tests directory was not copied to \"${SOURCE_TESTS_DIR}\"."
478 if [ "x${TEST}" = "xyes" ]; then
479 echo "WARNING: Disabling tests for this installation."
484 # Replace cluster and domain name in the test files
485 for f in $(ls "${SOURCE_TESTS_DIR}"/*); do
486 FILTERS="s#__CLUSTER__#${CLUSTER}#g;
487 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
488 s#__DOMAIN__#${DOMAIN}#g;
489 s#__IP_INT__#${IP_INT}#g;
490 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
491 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g
492 s#__INITIAL_USER__#${INITIAL_USER}#g;
493 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
494 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g"
495 if [ "$USE_SINGLE_HOSTNAME" = "yes" ]; then
496 FILTERS="s#__CLUSTER__.__DOMAIN__#${HOSTNAME_EXT}#g;
500 "${f}" > ${T_DIR}/$(basename "${f}")
502 chmod 755 ${T_DIR}/run-test.sh
505 # Replace helper state files that differ from the formula's examples
506 if [ -d "${SOURCE_STATES_DIR}" ]; then
507 mkdir -p "${F_DIR}"/extra/extra
508 rm -f "${F_DIR}"/extra/extra/*
510 for f in $(ls "${SOURCE_STATES_DIR}"/*); do
511 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
512 s#__CLUSTER__#${CLUSTER}#g;
513 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
514 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
515 s#__DOMAIN__#${DOMAIN}#g;
516 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
517 s#__IP_INT__#${IP_INT}#g;
518 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
519 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
520 s#__INITIAL_USER__#${INITIAL_USER}#g;
521 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
522 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
523 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
524 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
525 s#__RELEASE__#${RELEASE}#g;
526 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
527 s#__VERSION__#${VERSION}#g;
528 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
529 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
530 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
531 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
532 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
533 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
534 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
535 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
536 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
537 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
538 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
539 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
540 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
541 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
542 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
543 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g;
544 s#__SSL_KEY_ENCRYPTED__#${SSL_KEY_ENCRYPTED}#g;
545 s#__SSL_KEY_AWS_REGION__#${SSL_KEY_AWS_REGION}#g;
546 s#__SSL_KEY_AWS_SECRET_NAME__#${SSL_KEY_AWS_SECRET_NAME}#g;
547 s#__CONTROLLER_NGINX_WORKERS__#${CONTROLLER_NGINX_WORKERS}#g;
548 s#__CONTROLLER_MAX_CONCURRENT_REQUESTS__#${CONTROLLER_MAX_CONCURRENT_REQUESTS}#g;
549 s#__MONITORING_USERNAME__#${MONITORING_USERNAME}#g;
550 s#__MONITORING_EMAIL__#${MONITORING_EMAIL}#g;
551 s#__MONITORING_PASSWORD__#${MONITORING_PASSWORD}#g;
552 s#__DISPATCHER_SSH_PRIVKEY__#${DISPATCHER_SSH_PRIVKEY//$'\n'/\\n}#g;
553 s#__ENABLE_BALANCER__#${ENABLE_BALANCER}#g;
554 s#__DISABLED_CONTROLLER__#${DISABLED_CONTROLLER}#g;
555 s#__BALANCER_NODENAME__#${ROLES['balancer']}#g;
556 s#__PROMETHEUS_NODENAME__#${ROLES['monitoring']}#g;
557 s#__CONTROLLER_NODES__#${ROLES['controller']}#g;
558 s#__NODELIST__#${NODELIST}#g;
559 s#__DISPATCHER_INT_IP__#${DISPATCHER_INT_IP}#g;
560 s#__KEEPBALANCE_INT_IP__#${KEEPBALANCE_INT_IP}#g;
561 s#__COMPUTE_AMI__#${COMPUTE_AMI}#g;
562 s#__COMPUTE_SG__#${COMPUTE_SG}#g;
563 s#__COMPUTE_SUBNET__#${COMPUTE_SUBNET}#g;
564 s#__COMPUTE_AWS_REGION__#${COMPUTE_AWS_REGION}#g;
565 s#__COMPUTE_USER__#${COMPUTE_USER}#g;
566 s#__KEEP_AWS_REGION__#${KEEP_AWS_REGION}#g" \
567 "${f}" > "${F_DIR}/extra/extra"/$(basename "${f}")
571 # Now, we build the SALT states/pillars trees
572 # As we need to separate both states and pillars in case we want specific
573 # roles, we iterate on both at the same time
575 # Formula template overrides (TOFS)
576 # See: https://template-formula.readthedocs.io/en/latest/TOFS_pattern.html#template-override
577 if [ -d ${SOURCE_TOFS_DIR} ]; then
578 find ${SOURCE_TOFS_DIR} -mindepth 1 -maxdepth 1 -type d -exec cp -r "{}" ${S_DIR} \;
582 cat > ${S_DIR}/top.sls << EOFTSLS
589 cat > ${P_DIR}/top.sls << EOFPSLS
596 # States, extra states
597 if [ -d "${F_DIR}"/extra/extra ]; then
598 SKIP_SNAKE_OIL="snakeoil_certs"
600 if [[ "$DEV_MODE" = "yes" || "${SSL_MODE}" == "self-signed" ]] ; then
601 # In dev mode, we create some snake oil certs that we'll
602 # use as CUSTOM_CERTS, so we don't skip the states file.
603 # Same when using self-signed certificates.
604 SKIP_SNAKE_OIL="dont_add_snakeoil_certs"
606 for f in $(ls "${F_DIR}"/extra/extra/*.sls | egrep -v "${SKIP_SNAKE_OIL}|shell_"); do
607 echo " - extra.$(basename ${f} | sed 's/.sls$//g')" >> ${S_DIR}/top.sls
609 # Use byo or self-signed certificates
610 if [ "${SSL_MODE}" != "lets-encrypt" ]; then
611 mkdir -p "${F_DIR}"/extra/extra/files
615 # If we want specific roles for a node, just add the desired states
616 # and its dependencies
617 if [ -z "${ROLES}" ]; then
619 echo " - nginx.passenger" >> ${S_DIR}/top.sls
620 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
621 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
622 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - extra.aws_credentials" >> ${S_DIR}/top.sls
624 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
626 mkdir -p --mode=0700 /srv/salt/certs
627 if [ "${SSL_MODE}" = "bring-your-own" ]; then
628 # Copy certs to formula extra/files
629 install --mode=0600 ${CUSTOM_CERTS_DIR}/* /srv/salt/certs/
630 # We add the custom_certs state
631 grep -q "custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
632 if [ "${SSL_KEY_ENCRYPTED}" = "yes" ]; then
633 grep -q "ssl_key_encrypted" ${S_DIR}/top.sls || echo " - extra.ssl_key_encrypted" >> ${S_DIR}/top.sls
636 # In self-signed mode, the certificate files will be created and put in the
637 # destination directory by the snakeoil_certs.sls state file
640 echo " - postgres" >> ${S_DIR}/top.sls
641 echo " - logrotate" >> ${S_DIR}/top.sls
642 echo " - docker.software" >> ${S_DIR}/top.sls
643 echo " - arvados" >> ${S_DIR}/top.sls
644 echo " - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
645 echo " - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
646 echo " - extra.passenger_rvm" >> ${S_DIR}/top.sls
649 echo " - docker" >> ${P_DIR}/top.sls
650 echo " - nginx_api_configuration" >> ${P_DIR}/top.sls
651 echo " - logrotate_api" >> ${P_DIR}/top.sls
652 echo " - nginx_controller_configuration" >> ${P_DIR}/top.sls
653 echo " - nginx_keepproxy_configuration" >> ${P_DIR}/top.sls
654 echo " - nginx_keepweb_configuration" >> ${P_DIR}/top.sls
655 echo " - nginx_passenger" >> ${P_DIR}/top.sls
656 echo " - nginx_websocket_configuration" >> ${P_DIR}/top.sls
657 echo " - nginx_webshell_configuration" >> ${P_DIR}/top.sls
658 echo " - nginx_workbench2_configuration" >> ${P_DIR}/top.sls
659 echo " - nginx_workbench_configuration" >> ${P_DIR}/top.sls
660 echo " - logrotate_wb1" >> ${P_DIR}/top.sls
661 echo " - postgresql" >> ${P_DIR}/top.sls
663 # We need to tweak the Nginx's pillar depending whether we want plan nginx or nginx+passenger
664 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
665 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
667 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
668 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
669 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
671 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
673 hosts=("controller" "websocket" "workbench" "workbench2" "webshell" "keepproxy")
674 if [ ${USE_SINGLE_HOSTNAME} = "no" ]; then
675 hosts+=("download" "collections")
680 for c in "${hosts[@]}"; do
681 # Are we in a single-host-single-hostname env?
682 if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
683 # Are we in a single-host-single-hostname env?
684 CERT_NAME=${HOSTNAME_EXT}
686 # We are in a multiple-hostnames env
687 CERT_NAME=${c}.${DOMAIN}
690 # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
691 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${CERT_NAME}*/g;
692 s#__CERT_PEM__#/etc/letsencrypt/live/${CERT_NAME}/fullchain.pem#g;
693 s#__CERT_KEY__#/etc/letsencrypt/live/${CERT_NAME}/privkey.pem#g" \
694 ${P_DIR}/nginx_${c}_configuration.sls
697 # Use custom certs (either dev mode or prod)
698 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
699 # And add the certs in the custom_certs pillar
700 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
701 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
703 for c in controller websocket workbench workbench2 webshell keepweb keepproxy; do
704 # Are we in a single-host-single-hostname env?
705 if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
706 # Are we in a single-host-single-hostname env?
707 CERT_NAME=${HOSTNAME_EXT}
709 # We are in a multiple-hostnames env
713 if [[ "$SSL_MODE" == "bring-your-own" ]]; then
714 copy_custom_cert ${CUSTOM_CERTS_DIR} ${CERT_NAME}
717 grep -q ${CERT_NAME} ${P_DIR}/extra_custom_certs.sls || echo " - ${CERT_NAME}" >> ${P_DIR}/extra_custom_certs.sls
719 # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
720 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${CERT_NAME}.pem/g;
721 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${CERT_NAME}.pem#g;
722 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${CERT_NAME}.key#g" \
723 ${P_DIR}/nginx_${c}_configuration.sls
727 # If we add individual roles, make sure we add the repo first
728 echo " - arvados.repo" >> ${S_DIR}/top.sls
729 # We add the extra_custom_certs state
730 grep -q "extra.custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
731 if [ "${SSL_KEY_ENCRYPTED}" = "yes" ]; then
732 grep -q "ssl_key_encrypted" ${S_DIR}/top.sls || echo " - extra.ssl_key_encrypted" >> ${S_DIR}/top.sls
735 # And we add the basic part for the certs pillar
736 if [ "${SSL_MODE}" != "lets-encrypt" ]; then
737 # And add the certs in the custom_certs pillar
738 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
739 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
740 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
743 # Prometheus state on all nodes due to the node exporter below
744 grep -q "\- prometheus$" ${S_DIR}/top.sls || echo " - prometheus" >> ${S_DIR}/top.sls
745 # Prometheus node exporter pillar
746 grep -q "prometheus_node_exporter" ${P_DIR}/top.sls || echo " - prometheus_node_exporter" >> ${P_DIR}/top.sls
748 for R in ${ROLES}; do
752 grep -q "\- postgres$" ${S_DIR}/top.sls || echo " - postgres" >> ${S_DIR}/top.sls
753 grep -q "extra.prometheus_pg_exporter" ${S_DIR}/top.sls || echo " - extra.prometheus_pg_exporter" >> ${S_DIR}/top.sls
755 grep -q "postgresql" ${P_DIR}/top.sls || echo " - postgresql" >> ${P_DIR}/top.sls
756 grep -q "prometheus_pg_exporter" ${P_DIR}/top.sls || echo " - prometheus_pg_exporter" >> ${P_DIR}/top.sls
759 ### Support files ###
760 GRAFANA_DASHBOARDS_DEST_DIR=/srv/salt/dashboards
761 mkdir -p "${GRAFANA_DASHBOARDS_DEST_DIR}"
762 rm -f "${GRAFANA_DASHBOARDS_DEST_DIR}"/*
763 # "ArvadosPromDataSource" is the hardcoded UID for Prometheus' datasource
765 for f in $(ls "${GRAFANA_DASHBOARDS_DIR}"/*.json); do
766 sed 's#${DS_PROMETHEUS}#ArvadosPromDataSource#g' \
767 "${f}" > "${GRAFANA_DASHBOARDS_DEST_DIR}"/$(basename "${f}")
771 grep -q "\- nginx$" ${S_DIR}/top.sls || echo " - nginx" >> ${S_DIR}/top.sls
772 grep -q "extra.nginx_prometheus_configuration" ${S_DIR}/top.sls || echo " - extra.nginx_prometheus_configuration" >> ${S_DIR}/top.sls
774 grep -q "\- grafana$" ${S_DIR}/top.sls || echo " - grafana" >> ${S_DIR}/top.sls
775 grep -q "extra.grafana_datasource" ${S_DIR}/top.sls || echo " - extra.grafana_datasource" >> ${S_DIR}/top.sls
776 grep -q "extra.grafana_dashboards" ${S_DIR}/top.sls || echo " - extra.grafana_dashboards" >> ${S_DIR}/top.sls
777 grep -q "extra.grafana_admin_user" ${S_DIR}/top.sls || echo " - extra.grafana_admin_user" >> ${S_DIR}/top.sls
779 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
780 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
781 if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
782 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
784 elif [ "${SSL_MODE}" = "bring-your-own" ]; then
785 for SVC in grafana prometheus; do
786 copy_custom_cert ${CUSTOM_CERTS_DIR} ${SVC}
790 grep -q "prometheus_server" ${P_DIR}/top.sls || echo " - prometheus_server" >> ${P_DIR}/top.sls
791 grep -q "grafana" ${P_DIR}/top.sls || echo " - grafana" >> ${P_DIR}/top.sls
792 for SVC in grafana prometheus; do
793 grep -q "nginx_${SVC}_configuration" ${P_DIR}/top.sls || echo " - nginx_${SVC}_configuration" >> ${P_DIR}/top.sls
795 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
796 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
797 for SVC in grafana prometheus; do
798 grep -q "letsencrypt_${SVC}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${SVC}_configuration" >> ${P_DIR}/top.sls
799 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${SVC}.${DOMAIN}*/g;
800 s#__CERT_PEM__#/etc/letsencrypt/live/${SVC}.${DOMAIN}/fullchain.pem#g;
801 s#__CERT_KEY__#/etc/letsencrypt/live/${SVC}.${DOMAIN}/privkey.pem#g" \
802 ${P_DIR}/nginx_${SVC}_configuration.sls
804 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
805 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
807 elif [ "${SSL_MODE}" = "bring-your-own" ]; then
808 grep -q "ssl_key_encrypted" ${P_DIR}/top.sls || echo " - ssl_key_encrypted" >> ${P_DIR}/top.sls
809 for SVC in grafana prometheus; do
810 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${SVC}.pem/g;
811 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${SVC}.pem#g;
812 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${SVC}.key#g" \
813 ${P_DIR}/nginx_${SVC}_configuration.sls
814 grep -q ${SVC} ${P_DIR}/extra_custom_certs.sls || echo " - ${SVC}" >> ${P_DIR}/extra_custom_certs.sls
820 grep -q " - logrotate" ${S_DIR}/top.sls || echo " - logrotate" >> ${S_DIR}/top.sls
821 if grep -q " - nginx.*$" ${S_DIR}/top.sls; then
822 sed -i s/"^ - nginx.*$"/" - nginx.passenger"/g ${S_DIR}/top.sls
824 echo " - nginx.passenger" >> ${S_DIR}/top.sls
826 echo " - extra.passenger_rvm" >> ${S_DIR}/top.sls
827 ### If we don't install and run LE before arvados-api-server, it fails and breaks everything
828 ### after it. So we add this here as we are, after all, sharing the host for api and controller
829 if [ "${ENABLE_BALANCER}" == "no" ]; then
830 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
831 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
832 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
834 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
837 if [ "${SSL_MODE}" = "bring-your-own" ]; then
838 copy_custom_cert ${CUSTOM_CERTS_DIR} controller
840 grep -q controller ${P_DIR}/extra_custom_certs.sls || echo " - controller" >> ${P_DIR}/extra_custom_certs.sls
843 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
845 grep -q "logrotate_api" ${P_DIR}/top.sls || echo " - logrotate_api" >> ${P_DIR}/top.sls
846 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
847 grep -q "postgresql" ${P_DIR}/top.sls || echo " - postgresql" >> ${P_DIR}/top.sls
848 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
849 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
851 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
852 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
853 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
857 grep -q "\- nginx$" ${S_DIR}/top.sls || echo " - nginx" >> ${S_DIR}/top.sls
859 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
860 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
861 if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
862 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
864 elif [ "${SSL_MODE}" = "bring-your-own" ]; then
865 copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
869 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
871 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
872 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
874 grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
875 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${ROLES['balancer']}*/g;
876 s#__CERT_PEM__#/etc/letsencrypt/live/${ROLES['balancer']}/fullchain.pem#g;
877 s#__CERT_KEY__#/etc/letsencrypt/live/${ROLES['balancer']}/privkey.pem#g" \
878 ${P_DIR}/nginx_${R}_configuration.sls
880 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
881 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
883 elif [ "${SSL_MODE}" = "bring-your-own" ]; then
884 grep -q "ssl_key_encrypted" ${P_DIR}/top.sls || echo " - ssl_key_encrypted" >> ${P_DIR}/top.sls
885 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
886 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
887 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
888 ${P_DIR}/nginx_${R}_configuration.sls
889 grep -q "${R}" ${P_DIR}/extra_custom_certs.sls || echo " - ${R}" >> ${P_DIR}/extra_custom_certs.sls
894 grep -q "\- nginx$" ${S_DIR}/top.sls || echo " - nginx" >> ${S_DIR}/top.sls
895 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
897 if [ "${ENABLE_BALANCER}" == "no" ]; then
898 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
899 if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
900 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
902 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
903 elif [ "${SSL_MODE}" = "bring-your-own" ]; then
904 copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
909 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
910 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
912 if [ "${ENABLE_BALANCER}" == "no" ]; then
913 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
914 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
915 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
918 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
919 grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
920 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${R}.${DOMAIN}*/g;
921 s#__CERT_PEM__#/etc/letsencrypt/live/${R}.${DOMAIN}/fullchain.pem#g;
922 s#__CERT_KEY__#/etc/letsencrypt/live/${R}.${DOMAIN}/privkey.pem#g" \
923 ${P_DIR}/nginx_${R}_configuration.sls
925 grep -q "ssl_key_encrypted" ${P_DIR}/top.sls || echo " - ssl_key_encrypted" >> ${P_DIR}/top.sls
926 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
927 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
928 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
929 ${P_DIR}/nginx_${R}_configuration.sls
930 grep -q ${R} ${P_DIR}/extra_custom_certs.sls || echo " - ${R}" >> ${P_DIR}/extra_custom_certs.sls
933 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
934 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
936 "websocket" | "workbench" | "workbench2" | "webshell" | "keepweb" | "keepproxy")
938 if [ "${R}" = "workbench" ]; then
939 grep -q " - logrotate" ${S_DIR}/top.sls || echo " - logrotate" >> ${S_DIR}/top.sls
940 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
941 if grep -q " - nginx$" ${S_DIR}/top.sls; then
942 sed -i s/"^ - nginx.*$"/" - nginx.passenger"/g ${S_DIR}/top.sls
944 echo " - nginx.passenger" >> ${S_DIR}/top.sls
947 grep -q "\- nginx$" ${S_DIR}/top.sls || echo " - nginx" >> ${S_DIR}/top.sls
950 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
951 if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
952 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
954 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
956 # Use custom certs, special case for keepweb
957 if [ ${R} = "keepweb" ]; then
958 if [ "${SSL_MODE}" = "bring-your-own" ]; then
959 copy_custom_cert ${CUSTOM_CERTS_DIR} download
960 copy_custom_cert ${CUSTOM_CERTS_DIR} collections
963 if [ "${SSL_MODE}" = "bring-your-own" ]; then
964 copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
969 # webshell role is just a nginx vhost, so it has no state
970 if [ "${R}" != "webshell" ]; then
971 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
975 if [ "${R}" = "workbench" ]; then
976 grep -q "logrotate_wb1" ${P_DIR}/top.sls || echo " - logrotate_wb1" >> ${P_DIR}/top.sls
978 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
979 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
980 # Special case for keepweb
981 if [ ${R} = "keepweb" ]; then
982 grep -q "nginx_download_configuration" ${P_DIR}/top.sls || echo " - nginx_download_configuration" >> ${P_DIR}/top.sls
983 grep -q "nginx_collections_configuration" ${P_DIR}/top.sls || echo " - nginx_collections_configuration" >> ${P_DIR}/top.sls
986 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
987 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
988 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
990 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
991 grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
993 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
994 # Special case for keepweb
995 if [ ${R} = "keepweb" ]; then
996 for kwsub in download collections; do
997 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${kwsub}.${DOMAIN}*/g;
998 s#__CERT_PEM__#/etc/letsencrypt/live/${kwsub}.${DOMAIN}/fullchain.pem#g;
999 s#__CERT_KEY__#/etc/letsencrypt/live/${kwsub}.${DOMAIN}/privkey.pem#g" \
1000 ${P_DIR}/nginx_${kwsub}_configuration.sls
1003 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${R}.${DOMAIN}*/g;
1004 s#__CERT_PEM__#/etc/letsencrypt/live/${R}.${DOMAIN}/fullchain.pem#g;
1005 s#__CERT_KEY__#/etc/letsencrypt/live/${R}.${DOMAIN}/privkey.pem#g" \
1006 ${P_DIR}/nginx_${R}_configuration.sls
1009 grep -q "ssl_key_encrypted" ${P_DIR}/top.sls || echo " - ssl_key_encrypted" >> ${P_DIR}/top.sls
1010 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
1011 # Special case for keepweb
1012 if [ ${R} = "keepweb" ]; then
1013 for kwsub in download collections; do
1014 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${kwsub}.pem/g;
1015 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${kwsub}.pem#g;
1016 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${kwsub}.key#g" \
1017 ${P_DIR}/nginx_${kwsub}_configuration.sls
1018 grep -q ${kwsub} ${P_DIR}/extra_custom_certs.sls || echo " - ${kwsub}" >> ${P_DIR}/extra_custom_certs.sls
1021 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
1022 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
1023 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
1024 ${P_DIR}/nginx_${R}_configuration.sls
1025 grep -q ${R} ${P_DIR}/extra_custom_certs.sls || echo " - ${R}" >> ${P_DIR}/extra_custom_certs.sls
1028 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
1029 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
1033 echo " - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
1034 echo " - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
1035 grep -q "docker" ${S_DIR}/top.sls || echo " - docker.software" >> ${S_DIR}/top.sls
1036 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
1038 grep -q "docker" ${P_DIR}/top.sls || echo " - docker" >> ${P_DIR}/top.sls
1040 "dispatcher" | "keepbalance" | "keepstore")
1042 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
1044 # ATM, no specific pillar needed
1047 echo "Unknown role ${R}"
1054 if [ "${DUMP_CONFIG}" = "yes" ]; then
1055 # We won't run the rest of the script because we're just dumping the config
1059 # Now run the install
1060 salt-call --state-output=mixed --local state.apply -l ${LOG_LEVEL}
1062 # Finally, make sure that /etc/hosts is not overwritten on reboot
1063 if [ -d /etc/cloud/cloud.cfg.d ]; then
1064 # TODO: will this work on CentOS?
1065 sed -i 's/^manage_etc_hosts: true/#manage_etc_hosts: true/g' /etc/cloud/cloud.cfg.d/*
1068 # Leave a copy of the Arvados CA so the user can copy it where it's required
1069 if [ "${SSL_MODE}" = "self-signed" ]; then
1070 echo "Copying the Arvados CA certificate '${DOMAIN}-arvados-snakeoil-ca.crt' to the installer dir, so you can import it"
1071 if [ "x${VAGRANT}" = "xyes" ]; then
1072 cp /etc/ssl/certs/arvados-snakeoil-ca.pem /vagrant/${DOMAIN}-arvados-snakeoil-ca.pem
1074 cp /etc/ssl/certs/arvados-snakeoil-ca.pem ${SCRIPT_DIR}/${DOMAIN}-arvados-snakeoil-ca.crt
1078 if [ "x${VAGRANT}" = "xyes" ]; then
1079 # If running in a vagrant VM, also add default user to docker group
1080 echo "Adding the vagrant user to the docker group"
1081 usermod -a -G docker vagrant
1084 # Test that the installation finished correctly
1085 if [ "x${TEST}" = "xyes" ]; then
1087 # If we use RVM, we need to run this with it, or most ruby commands will fail
1089 if [ -x /usr/local/rvm/bin/rvm-exec ]; then
1090 RVM_EXEC="/usr/local/rvm/bin/rvm-exec"
1092 ${RVM_EXEC} ./run-test.sh