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:"
29 echo >&2 " controller"
30 echo >&2 " dispatcher"
38 echo >&2 " workbench2"
39 echo >&2 " Defaults to applying them all"
40 echo >&2 " -h, --help Display this help and exit"
41 echo >&2 " --dump-config <dest_dir> Dumps the pillars and states to a directory"
42 echo >&2 " This parameter does not perform any installation at all. It's"
43 echo >&2 " intended to give you a parsed sot of configuration files so"
44 echo >&2 " you can inspect them or use them in you Saltstack infrastructure."
46 echo >&2 " - parses the pillar and states templates,"
47 echo >&2 " - downloads the helper formulas with their desired versions,"
48 echo >&2 " - prepares the 'top.sls' files both for pillars and states"
49 echo >&2 " for the selected role/s"
50 echo >&2 " - writes the resulting files into <dest_dir>"
51 echo >&2 " -v, --vagrant Run in vagrant and use the /vagrant shared dir"
52 echo >&2 " --development Run in dev mode, using snakeoil certs"
57 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
58 if ! which getopt > /dev/null; then
59 echo >&2 "GNU getopt is required to run this script. Please install it and re-reun it"
63 TEMP=$(getopt -o c:dhp:r:tv \
64 --long config:,debug,development,dump-config:,help,roles:,test,vagrant \
68 then echo "Please check the parameters you entered and re-run again"
71 # Note the quotes around `$TEMP': they are essential!
74 while [ ${#} -ge 1 ]; do
86 if [[ ${2} = /* ]]; then
87 DUMP_SALT_CONFIG_DIR=${2}
89 DUMP_SALT_CONFIG_DIR=${PWD}/${2}
92 S_DIR="${DUMP_SALT_CONFIG_DIR}/salt"
94 F_DIR="${DUMP_SALT_CONFIG_DIR}/formulas"
96 P_DIR="${DUMP_SALT_CONFIG_DIR}/pillars"
98 T_DIR="${DUMP_SALT_CONFIG_DIR}/tests"
109 # Verify the role exists
110 if [[ ! "database,api,controller,keepstore,websocket,keepweb,workbench2,webshell,keepproxy,shell,workbench,dispatcher" == *"$i"* ]]; then
111 echo "The role '${i}' is not a valid role"
115 ROLES="${ROLES} ${i}"
143 mkdir -p /srv/salt/certs
144 cp -v ${cert_dir}/${cert_name}.crt /srv/salt/certs/arvados-${cert_name}.pem
145 cp -v ${cert_dir}/${cert_name}.key /srv/salt/certs/arvados-${cert_name}.key
149 CONFIG_FILE="${SCRIPT_DIR}/local.params"
150 CONFIG_DIR="local_config_dir"
153 CONTROLLER_EXT_SSL_PORT=443
159 # Hostnames/IPs used for single-host deploys
161 HOSTNAME_INT="127.0.1.1"
165 INITIAL_USER_EMAIL=""
166 INITIAL_USER_PASSWORD=""
168 CONTROLLER_EXT_SSL_PORT=8000
169 KEEP_EXT_SSL_PORT=25101
170 # Both for collections and downloads
171 KEEPWEB_EXT_SSL_PORT=9002
172 WEBSHELL_EXT_SSL_PORT=4202
173 WEBSOCKET_EXT_SSL_PORT=8002
174 WORKBENCH1_EXT_SSL_PORT=443
175 WORKBENCH2_EXT_SSL_PORT=3001
178 CUSTOM_CERTS_DIR="${SCRIPT_DIR}/certs"
180 ## These are ARVADOS-related parameters
181 # For a stable release, change RELEASE "production" and VERSION to the
182 # package version (including the iteration, e.g. X.Y.Z-1) of the
184 # The "local.params.example.*" files already set "RELEASE=production"
185 # to deploy production-ready packages
186 RELEASE="development"
189 # These are arvados-formula-related parameters
190 # An arvados-formula tag. For a stable release, this should be a
191 # branch name (e.g. X.Y-dev) or tag for the release.
192 # ARVADOS_TAG="2.2.0"
195 # Other formula versions we depend on
196 POSTGRES_TAG="v0.41.6"
197 NGINX_TAG="temp-fix-missing-statements-in-pillar"
200 LETSENCRYPT_TAG="v2.1.0"
203 DUMP_SALT_CONFIG_DIR=""
207 F_DIR="/srv/formulas"
211 T_DIR="/tmp/cluster_tests"
215 if [ -s ${CONFIG_FILE} ]; then
216 source ${CONFIG_FILE}
218 echo >&2 "You don't seem to have a config file with initial values."
219 echo >&2 "Please create a '${CONFIG_FILE}' file as described in"
220 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
221 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
225 if [ ! -d ${CONFIG_DIR} ]; then
226 echo >&2 "You don't seem to have a config directory with pillars and states."
227 echo >&2 "Please create a '${CONFIG_DIR}' directory (as configured in your '${CONFIG_FILE}'). Please see"
228 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
229 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
233 if grep -q 'fixme_or_this_wont_work' ${CONFIG_FILE} ; then
234 echo >&2 "The config file ${CONFIG_FILE} has some parameters that need to be modified."
235 echo >&2 "Please, fix them and re-run the provision script."
239 if ! grep -qE '^[[:alnum:]]{5}$' <<<${CLUSTER} ; then
240 echo >&2 "ERROR: <CLUSTER> must be exactly 5 alphanumeric characters long"
241 echo >&2 "Fix the cluster name in the 'local.params' file and re-run the provision script"
245 # Only used in single_host/single_name deploys
246 if [ "x${HOSTNAME_EXT}" = "x" ] ; then
247 HOSTNAME_EXT="${CLUSTER}.${DOMAIN}"
250 if [ "${DUMP_CONFIG}" = "yes" ]; then
251 echo "The provision installer will just dump a config under ${DUMP_SALT_CONFIG_DIR} and exit"
253 # Install a few dependency packages
254 # First, let's figure out the OS we're working on
255 OS_ID=$(grep ^ID= /etc/os-release |cut -f 2 -d= |cut -f 2 -d \")
256 echo "Detected distro: ${OS_ID}"
260 echo "WARNING! Disabling SELinux, see https://dev.arvados.org/issues/18019"
261 sed -i 's/SELINUX=enforcing/SELINUX=permissive' /etc/sysconfig/selinux
262 setenforce permissive
263 yum install -y curl git jq
266 DEBIAN_FRONTEND=noninteractive apt update
267 DEBIAN_FRONTEND=noninteractive apt install -y curl git jq
271 if which salt-call; then
272 echo "Salt already installed"
274 curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
275 sh /tmp/bootstrap_salt.sh -XdfP -x python3
276 /bin/systemctl stop salt-minion.service
277 /bin/systemctl disable salt-minion.service
280 # Set salt to masterless mode
281 cat > /etc/salt/minion << EOFSM
296 mkdir -p ${S_DIR} ${F_DIR} ${P_DIR} ${T_DIR}
298 # Get the formula and dependencies
299 cd ${F_DIR} || exit 1
300 echo "Cloning formulas"
301 rm -rf ${F_DIR}/* || exit 1
302 git clone --quiet https://github.com/saltstack-formulas/docker-formula.git ${F_DIR}/docker
303 ( cd docker && git checkout --quiet tags/"${DOCKER_TAG}" -b "${DOCKER_TAG}" )
305 git clone --quiet https://github.com/saltstack-formulas/locale-formula.git ${F_DIR}/locale
306 ( cd locale && git checkout --quiet tags/"${LOCALE_TAG}" -b "${LOCALE_TAG}" )
308 git clone --quiet https://github.com/netmanagers/nginx-formula.git ${F_DIR}/nginx
309 ( cd nginx && git checkout --quiet tags/"${NGINX_TAG}" -b "${NGINX_TAG}" )
311 git clone --quiet https://github.com/saltstack-formulas/postgres-formula.git ${F_DIR}/postgres
312 ( cd postgres && git checkout --quiet tags/"${POSTGRES_TAG}" -b "${POSTGRES_TAG}" )
314 git clone --quiet https://github.com/saltstack-formulas/letsencrypt-formula.git ${F_DIR}/letsencrypt
315 ( cd letsencrypt && git checkout --quiet tags/"${LETSENCRYPT_TAG}" -b "${LETSENCRYPT_TAG}" )
317 git clone --quiet https://git.arvados.org/arvados-formula.git ${F_DIR}/arvados
319 # If we want to try a specific branch of the formula
320 if [ "x${BRANCH}" != "x" ]; then
321 ( cd ${F_DIR}/arvados && git checkout --quiet -t origin/"${BRANCH}" -b "${BRANCH}" )
322 elif [ "x${ARVADOS_TAG}" != "x" ]; then
323 ( cd ${F_DIR}/arvados && git checkout --quiet tags/"${ARVADOS_TAG}" -b "${ARVADOS_TAG}" )
326 if [ "x${VAGRANT}" = "xyes" ]; then
327 EXTRA_STATES_DIR="/home/vagrant/${CONFIG_DIR}/states"
328 SOURCE_PILLARS_DIR="/home/vagrant/${CONFIG_DIR}/pillars"
329 SOURCE_TESTS_DIR="/home/vagrant/${TESTS_DIR}"
331 EXTRA_STATES_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/states"
332 SOURCE_PILLARS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/pillars"
333 SOURCE_TESTS_DIR="${SCRIPT_DIR}/${TESTS_DIR}"
336 SOURCE_STATES_DIR="${EXTRA_STATES_DIR}"
338 echo "Writing pillars and states"
340 # Replace variables (cluster, domain, etc) in the pillars, states and tests
341 # to ease deployment for newcomers
342 if [ ! -d "${SOURCE_PILLARS_DIR}" ]; then
343 echo "${SOURCE_PILLARS_DIR} does not exist or is not a directory. Exiting."
346 for f in $(ls "${SOURCE_PILLARS_DIR}"/*); do
347 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
348 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
349 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
350 s#__CLUSTER__#${CLUSTER}#g;
351 s#__DOMAIN__#${DOMAIN}#g;
352 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
353 s#__HOSTNAME_INT__#${HOSTNAME_INT}#g;
354 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
355 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
356 s#__INITIAL_USER__#${INITIAL_USER}#g;
357 s#__LE_AWS_REGION__#${LE_AWS_REGION}#g;
358 s#__LE_AWS_SECRET_ACCESS_KEY__#${LE_AWS_SECRET_ACCESS_KEY}#g;
359 s#__LE_AWS_ACCESS_KEY_ID__#${LE_AWS_ACCESS_KEY_ID}#g;
360 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
361 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
362 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
363 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
364 s#__RELEASE__#${RELEASE}#g;
365 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
366 s#__VERSION__#${VERSION}#g;
367 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
368 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
369 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
370 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
371 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
372 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
373 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
374 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
375 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
376 s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
377 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
378 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
379 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
380 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
381 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
382 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
383 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g" \
384 "${f}" > "${P_DIR}"/$(basename "${f}")
387 if [ "x${TEST}" = "xyes" ] && [ ! -d "${SOURCE_TESTS_DIR}" ]; then
388 echo "You requested to run tests, but ${SOURCE_TESTS_DIR} does not exist or is not a directory. Exiting."
392 # Replace cluster and domain name in the test files
393 for f in $(ls "${SOURCE_TESTS_DIR}"/*); do
394 sed "s#__CLUSTER__#${CLUSTER}#g;
395 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
396 s#__DOMAIN__#${DOMAIN}#g;
397 s#__HOSTNAME_INT__#${HOSTNAME_INT}#g;
398 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
399 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g
400 s#__INITIAL_USER__#${INITIAL_USER}#g;
401 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
402 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g" \
403 "${f}" > ${T_DIR}/$(basename "${f}")
405 chmod 755 ${T_DIR}/run-test.sh
407 # Replace helper state files that differ from the formula's examples
408 if [ -d "${SOURCE_STATES_DIR}" ]; then
409 mkdir -p "${F_DIR}"/extra/extra
411 for f in $(ls "${SOURCE_STATES_DIR}"/*); do
412 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
413 s#__CLUSTER__#${CLUSTER}#g;
414 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
415 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
416 s#__DOMAIN__#${DOMAIN}#g;
417 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
418 s#__HOSTNAME_INT__#${HOSTNAME_INT}#g;
419 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
420 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
421 s#__INITIAL_USER__#${INITIAL_USER}#g;
422 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
423 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
424 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
425 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
426 s#__RELEASE__#${RELEASE}#g;
427 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
428 s#__VERSION__#${VERSION}#g;
429 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
430 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
431 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
432 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
433 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
434 s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
435 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
436 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
437 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
438 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
439 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
440 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
441 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
442 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
443 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
444 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g" \
445 "${f}" > "${F_DIR}/extra/extra"/$(basename "${f}")
449 # Now, we build the SALT states/pillars trees
450 # As we need to separate both states and pillars in case we want specific
451 # roles, we iterate on both at the same time
454 cat > ${S_DIR}/top.sls << EOFTSLS
461 cat > ${P_DIR}/top.sls << EOFPSLS
468 # States, extra states
469 if [ -d "${F_DIR}"/extra/extra ]; then
470 if [ "$DEV_MODE" = "yes" ]; then
471 # In dev mode, we create some snake oil certs that we'll
472 # use as CUSTOM_CERTS, so we don't skip the states file
473 SKIP_SNAKE_OIL="dont_snakeoil_certs"
475 SKIP_SNAKE_OIL="snakeoil_certs"
477 for f in $(ls "${F_DIR}"/extra/extra/*.sls | grep -v ${SKIP_SNAKE_OIL}); do
478 echo " - extra.$(basename ${f} | sed 's/.sls$//g')" >> ${S_DIR}/top.sls
481 if [ "x${USE_LETSENCRYPT}" != "xyes" ]; then
482 mkdir -p "${F_DIR}"/extra/extra/files
486 # If we want specific roles for a node, just add the desired states
487 # and its dependencies
488 if [ -z "${ROLES}" ]; then
490 echo " - nginx.passenger" >> ${S_DIR}/top.sls
491 # Currently, only available on config_examples/multi_host/aws
492 if [ "x${USE_LETSENCRYPT}" = "xyes" ]; then
493 if [ "x${USE_LETSENCRYPT_IAM_USER}" != "xyes" ]; then
494 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - extra.aws_credentials" >> ${S_DIR}/top.sls
496 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
499 # Copy certs to formula extra/files
500 # In dev mode, the files will be created and put in the destination directory by the
501 # snakeoil_certs.sls state file
502 mkdir -p /srv/salt/certs
503 cp -rv ${CUSTOM_CERTS_DIR}/* /srv/salt/certs/
504 # We add the custom_certs state
505 grep -q "custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
508 echo " - postgres" >> ${S_DIR}/top.sls
509 echo " - docker.software" >> ${S_DIR}/top.sls
510 echo " - arvados" >> ${S_DIR}/top.sls
513 echo " - docker" >> ${P_DIR}/top.sls
514 echo " - nginx_api_configuration" >> ${P_DIR}/top.sls
515 echo " - nginx_controller_configuration" >> ${P_DIR}/top.sls
516 echo " - nginx_keepproxy_configuration" >> ${P_DIR}/top.sls
517 echo " - nginx_keepweb_configuration" >> ${P_DIR}/top.sls
518 echo " - nginx_passenger" >> ${P_DIR}/top.sls
519 echo " - nginx_websocket_configuration" >> ${P_DIR}/top.sls
520 echo " - nginx_webshell_configuration" >> ${P_DIR}/top.sls
521 echo " - nginx_workbench2_configuration" >> ${P_DIR}/top.sls
522 echo " - nginx_workbench_configuration" >> ${P_DIR}/top.sls
523 echo " - postgresql" >> ${P_DIR}/top.sls
525 # Currently, only available on config_examples/multi_host/aws
526 if [ "x${USE_LETSENCRYPT}" = "xyes" ]; then
527 if [ "x${USE_LETSENCRYPT_IAM_USER}" != "xyes" ]; then
528 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
530 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
532 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
533 for c in controller websocket workbench workbench2 webshell download collections keepproxy; do
534 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${c}.${CLUSTER}.${DOMAIN}*/g;
535 s#__CERT_PEM__#/etc/letsencrypt/live/${c}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
536 s#__CERT_KEY__#/etc/letsencrypt/live/${c}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
537 ${P_DIR}/nginx_${c}_configuration.sls
540 # Use custom certs (either dev mode or prod)
541 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
542 # And add the certs in the custom_certs pillar
543 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
544 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
546 for c in controller websocket workbench workbench2 webshell download collections keepproxy; do
547 grep -q ${c} ${P_DIR}/extra_custom_certs.sls || echo " - ${c}" >> ${P_DIR}/extra_custom_certs.sls
549 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
550 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${c}.pem/g;
551 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${c}.pem#g;
552 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${c}.key#g" \
553 ${P_DIR}/nginx_${c}_configuration.sls
557 # If we add individual roles, make sure we add the repo first
558 echo " - arvados.repo" >> ${S_DIR}/top.sls
559 # We add the custom_certs state
560 grep -q "custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
562 # And we add the basic part for the certs pillar
563 if [ "x${USE_LETSENCRYPT}" != "xyes" ]; then
564 # And add the certs in the custom_certs pillar
565 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
566 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
567 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
570 for R in ${ROLES}; do
574 echo " - postgres" >> ${S_DIR}/top.sls
576 echo ' - postgresql' >> ${P_DIR}/top.sls
580 # FIXME: https://dev.arvados.org/issues/17352
581 grep -q "postgres.client" ${S_DIR}/top.sls || echo " - postgres.client" >> ${S_DIR}/top.sls
582 grep -q "nginx.passenger" ${S_DIR}/top.sls || echo " - nginx.passenger" >> ${S_DIR}/top.sls
583 ### If we don't install and run LE before arvados-api-server, it fails and breaks everything
584 ### after it. So we add this here as we are, after all, sharing the host for api and controller
585 # Currently, only available on config_examples/multi_host/aws
586 if [ "x${USE_LETSENCRYPT}" = "xyes" ]; then
587 if [ "x${USE_LETSENCRYPT_IAM_USER}" != "xyes" ]; then
588 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
590 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
593 copy_custom_cert ${CUSTOM_CERTS_DIR} controller
594 grep -q controller ${P_DIR}/extra_custom_certs.sls || echo " - controller" >> ${P_DIR}/extra_custom_certs.sls
596 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
598 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
599 grep -q "docker" ${P_DIR}/top.sls || echo " - docker" >> ${P_DIR}/top.sls
600 grep -q "postgresql" ${P_DIR}/top.sls || echo " - postgresql" >> ${P_DIR}/top.sls
601 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
602 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
604 "controller" | "websocket" | "workbench" | "workbench2" | "webshell" | "keepweb" | "keepproxy")
606 grep -q "nginx.passenger" ${S_DIR}/top.sls || echo " - nginx.passenger" >> ${S_DIR}/top.sls
607 # Currently, only available on config_examples/multi_host/aws
608 if [ "x${USE_LETSENCRYPT}" = "xyes" ]; then
609 if [ "x${USE_LETSENCRYPT_IAM_USER}" != "xyes" ]; then
610 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
612 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
614 # Use custom certs, special case for keepweb
615 if [ ${R} = "keepweb" ]; then
616 copy_custom_cert ${CUSTOM_CERTS_DIR} download
617 copy_custom_cert ${CUSTOM_CERTS_DIR} collections
619 copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
622 # webshell role is just a nginx vhost, so it has no state
623 if [ "${R}" != "webshell" ]; then
624 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
627 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
628 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
629 # Special case for keepweb
630 if [ ${R} = "keepweb" ]; then
631 grep -q "nginx_download_configuration" ${P_DIR}/top.sls || echo " - nginx_download_configuration" >> ${P_DIR}/top.sls
632 grep -q "nginx_collections_configuration" ${P_DIR}/top.sls || echo " - nginx_collections_configuration" >> ${P_DIR}/top.sls
635 # Currently, only available on config_examples/multi_host/aws
636 if [ "x${USE_LETSENCRYPT}" = "xyes" ]; then
637 if [ "x${USE_LETSENCRYPT_IAM_USER}" != "xyes" ]; then
638 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
640 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
641 grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
643 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
644 # Special case for keepweb
645 if [ ${R} = "keepweb" ]; then
646 for kwsub in download collections; do
647 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${kwsub}.${CLUSTER}.${DOMAIN}*/g;
648 s#__CERT_PEM__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
649 s#__CERT_KEY__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
650 ${P_DIR}/nginx_${kwsub}_configuration.sls
653 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${R}.${CLUSTER}.${DOMAIN}*/g;
654 s#__CERT_PEM__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
655 s#__CERT_KEY__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
656 ${P_DIR}/nginx_${R}_configuration.sls
659 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
660 # Special case for keepweb
661 if [ ${R} = "keepweb" ]; then
662 for kwsub in download collections; do
663 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${kwsub}.pem/g;
664 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${kwsub}.pem#g;
665 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${kwsub}.key#g" \
666 ${P_DIR}/nginx_${kwsub}_configuration.sls
667 grep -q ${kwsub} ${P_DIR}/extra_custom_certs.sls || echo " - ${kwsub}" >> ${P_DIR}/extra_custom_certs.sls
670 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
671 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
672 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
673 ${P_DIR}/nginx_${R}_configuration.sls
674 grep -q ${R} ${P_DIR}/extra_custom_certs.sls || echo " - ${R}" >> ${P_DIR}/extra_custom_certs.sls
680 grep -q "docker" ${S_DIR}/top.sls || echo " - docker.software" >> ${S_DIR}/top.sls
681 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
683 grep -q "" ${P_DIR}/top.sls || echo " - docker" >> ${P_DIR}/top.sls
687 grep -q "docker" ${S_DIR}/top.sls || echo " - docker.software" >> ${S_DIR}/top.sls
688 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
690 # ATM, no specific pillar needed
694 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
696 # ATM, no specific pillar needed
699 echo "Unknown role ${R}"
706 if [ "${DUMP_CONFIG}" = "yes" ]; then
707 # We won't run the rest of the script because we're just dumping the config
711 # FIXME! #16992 Temporary fix for psql call in arvados-api-server
712 if [ -e /root/.psqlrc ]; then
713 if ! ( grep 'pset pager off' /root/.psqlrc ); then
715 cp /root/.psqlrc /root/.psqlrc.provision.backup
721 echo '\pset pager off' >> /root/.psqlrc
722 # END FIXME! #16992 Temporary fix for psql call in arvados-api-server
724 # Now run the install
725 salt-call --local state.apply -l ${LOG_LEVEL}
727 # FIXME! #16992 Temporary fix for psql call in arvados-api-server
728 if [ "x${DELETE_PSQL}" = "xyes" ]; then
729 echo "Removing .psql file"
733 if [ "x${RESTORE_PSQL}" = "xyes" ]; then
734 echo "Restoring .psql file"
735 mv -v /root/.psqlrc.provision.backup /root/.psqlrc
737 # END FIXME! #16992 Temporary fix for psql call in arvados-api-server
739 # Leave a copy of the Arvados CA so the user can copy it where it's required
740 if [ "$DEV_MODE" = "yes" ]; then
741 echo "Copying the Arvados CA certificate to the installer dir, so you can import it"
742 # If running in a vagrant VM, also add default user to docker group
743 if [ "x${VAGRANT}" = "xyes" ]; then
744 cp /etc/ssl/certs/arvados-snakeoil-ca.pem /vagrant/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
746 echo "Adding the vagrant user to the docker group"
747 usermod -a -G docker vagrant
749 cp /etc/ssl/certs/arvados-snakeoil-ca.pem ${SCRIPT_DIR}/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
753 # Test that the installation finished correctly
754 if [ "x${TEST}" = "xyes" ]; then
756 # If we use RVM, we need to run this with it, or most ruby commands will fail
758 if [ -x /usr/local/rvm/bin/rvm-exec ]; then
759 RVM_EXEC="/usr/local/rvm/bin/rvm-exec"
761 ${RVM_EXEC} ./run-test.sh