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"
32 echo >&2 " keepbalance"
39 echo >&2 " workbench2"
40 echo >&2 " Defaults to applying them all"
41 echo >&2 " -h, --help Display this help and exit"
42 echo >&2 " --dump-config <dest_dir> Dumps the pillars and states to a directory"
43 echo >&2 " This parameter does not perform any installation at all. It's"
44 echo >&2 " intended to give you a parsed set of configuration files so"
45 echo >&2 " you can inspect them or use them in you Saltstack infrastructure."
47 echo >&2 " - parses the pillar and states templates,"
48 echo >&2 " - downloads the helper formulas with their desired versions,"
49 echo >&2 " - prepares the 'top.sls' files both for pillars and states"
50 echo >&2 " for the selected role(s)"
51 echo >&2 " - writes the resulting files into <dest_dir>"
52 echo >&2 " -v, --vagrant Run in vagrant and use the /vagrant shared dir"
53 echo >&2 " --development Run in dev mode, using snakeoil certs"
58 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
59 if ! which getopt > /dev/null; then
60 echo >&2 "GNU getopt is required to run this script. Please install it and re-reun it"
64 TEMP=$(getopt -o c:dhp:r:tv \
65 --long config:,debug,development,dump-config:,help,roles:,test,vagrant \
69 then echo "Please check the parameters you entered and re-run again"
72 # Note the quotes around `$TEMP': they are essential!
75 while [ ${#} -ge 1 ]; do
87 if [[ ${2} = /* ]]; then
88 DUMP_SALT_CONFIG_DIR=${2}
90 DUMP_SALT_CONFIG_DIR=${PWD}/${2}
93 S_DIR="${DUMP_SALT_CONFIG_DIR}/salt"
95 F_DIR="${DUMP_SALT_CONFIG_DIR}/formulas"
97 P_DIR="${DUMP_SALT_CONFIG_DIR}/pillars"
99 T_DIR="${DUMP_SALT_CONFIG_DIR}/tests"
110 # Verify the role exists
111 if [[ ! "database,api,controller,keepstore,websocket,keepweb,workbench2,webshell,keepbalance,keepproxy,shell,workbench,dispatcher" == *"$i"* ]]; then
112 echo "The role '${i}' is not a valid role"
116 ROLES="${ROLES} ${i}"
144 mkdir -p /srv/salt/certs
146 if [ -f ${cert_dir}/${cert_name}.crt ]; then
147 cp -v ${cert_dir}/${cert_name}.crt /srv/salt/certs/arvados-${cert_name}.pem
149 echo "${cert_dir}/${cert_name}.crt does not exist. Exiting"
152 if [ -f ${cert_dir}/${cert_name}.key ]; then
153 cp -v ${cert_dir}/${cert_name}.key /srv/salt/certs/arvados-${cert_name}.key
155 echo "${cert_dir}/${cert_name}.key does not exist. Exiting"
161 CONFIG_FILE="${SCRIPT_DIR}/local.params"
162 CONFIG_DIR="local_config_dir"
165 CONTROLLER_EXT_SSL_PORT=443
168 NGINX_INSTALL_SOURCE="install_from_repo"
173 # Hostnames/IPs used for single-host deploys
178 INITIAL_USER_EMAIL=""
179 INITIAL_USER_PASSWORD=""
181 CONTROLLER_EXT_SSL_PORT=8000
182 KEEP_EXT_SSL_PORT=25101
183 # Both for collections and downloads
184 KEEPWEB_EXT_SSL_PORT=9002
185 WEBSHELL_EXT_SSL_PORT=4202
186 WEBSOCKET_EXT_SSL_PORT=8002
187 WORKBENCH1_EXT_SSL_PORT=443
188 WORKBENCH2_EXT_SSL_PORT=3001
190 SSL_MODE="self-signed"
191 USE_LETSENCRYPT_ROUTE53="no"
192 CUSTOM_CERTS_DIR="${SCRIPT_DIR}/local_config_dir/certs"
194 ## These are ARVADOS-related parameters
195 # For a stable release, change RELEASE "production" and VERSION to the
196 # package version (including the iteration, e.g. X.Y.Z-1) of the
198 # The "local.params.example.*" files already set "RELEASE=production"
199 # to deploy production-ready packages
200 RELEASE="development"
203 # These are arvados-formula-related parameters
204 # An arvados-formula tag. For a stable release, this should be a
205 # branch name (e.g. X.Y-dev) or tag for the release.
206 # ARVADOS_TAG="2.2.0"
209 # Other formula versions we depend on
210 POSTGRES_TAG="v0.44.0"
214 LETSENCRYPT_TAG="v2.1.0"
217 DUMP_SALT_CONFIG_DIR=""
221 F_DIR="/srv/formulas"
225 T_DIR="/tmp/cluster_tests"
231 if [ -s ${CONFIG_FILE} ]; then
232 source ${CONFIG_FILE}
234 echo >&2 "You don't seem to have a config file with initial values."
235 echo >&2 "Please create a '${CONFIG_FILE}' file as described in"
236 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
237 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
241 if [ ! -d ${CONFIG_DIR} ]; then
242 echo >&2 "You don't seem to have a config directory with pillars and states."
243 echo >&2 "Please create a '${CONFIG_DIR}' directory (as configured in your '${CONFIG_FILE}'). Please see"
244 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
245 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
249 if grep -rni 'fixme' ${CONFIG_FILE} ${CONFIG_DIR} ; then
250 echo >&2 "The config file ${CONFIG_FILE} has some parameters that need to be modified."
251 echo >&2 "Please, fix them and re-run the provision script."
255 if ! grep -qE '^[[:alnum:]]{5}$' <<<${CLUSTER} ; then
256 echo >&2 "ERROR: <CLUSTER> must be exactly 5 lowercase alphanumeric characters long"
257 echo >&2 "Fix the cluster name in the 'local.params' file and re-run the provision script"
261 # Only used in single_host/single_name deploys
262 if [ ! -z "${HOSTNAME_EXT}" ] ; then
263 # We need to add some extra control vars to manage a single certificate vs. multiple
264 USE_SINGLE_HOSTNAME="yes"
265 # Make sure that the value configured as IP_INT is a real IP on the system.
266 # If we don't error out early here when there is a mismatch, the formula will
267 # fail with hard to interpret nginx errors later on.
268 ip addr list |grep "${IP_INT}/" >/dev/null
269 if [[ $? -ne 0 ]]; then
270 echo "Unable to find the IP_INT address '${IP_INT}' on the system, please correct the value in local.params. Exiting..."
274 USE_SINGLE_HOSTNAME="no"
275 # We set this variable, anyway, so sed lines do not fail and we don't need to add more
277 HOSTNAME_EXT="${CLUSTER}.${DOMAIN}"
280 if [ "${DUMP_CONFIG}" = "yes" ]; then
281 echo "The provision installer will just dump a config under ${DUMP_SALT_CONFIG_DIR} and exit"
283 # Install a few dependency packages
284 # First, let's figure out the OS we're working on
285 OS_ID=$(grep ^ID= /etc/os-release |cut -f 2 -d= |cut -f 2 -d \")
286 echo "Detected distro: ${OS_ID}"
290 echo "WARNING! Disabling SELinux, see https://dev.arvados.org/issues/18019"
291 sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
292 setenforce permissive
293 yum install -y curl git jq
296 # Wait 2 minutes for any apt locks to clear
297 # This option is supported from apt 1.9.1 and ignored in older apt versions.
298 # Cf. https://blog.sinjakli.co.uk/2021/10/25/waiting-for-apt-locks-without-the-hacky-bash-scripts/
299 DEBIAN_FRONTEND=noninteractive apt -o DPkg::Lock::Timeout=120 update
300 DEBIAN_FRONTEND=noninteractive apt install -y curl git jq
304 if which salt-call; then
305 echo "Salt already installed"
307 curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
308 sh /tmp/bootstrap_salt.sh -XdfP -x python3
309 /bin/systemctl stop salt-minion.service
310 /bin/systemctl disable salt-minion.service
313 # Set salt to masterless mode
314 cat > /etc/salt/minion << EOFSM
329 mkdir -p ${S_DIR} ${F_DIR} ${P_DIR} ${T_DIR}
331 # Get the formula and dependencies
332 cd ${F_DIR} || exit 1
333 echo "Cloning formulas"
334 rm -rf ${F_DIR}/* || exit 1
335 git clone --quiet https://github.com/saltstack-formulas/docker-formula.git ${F_DIR}/docker
336 ( cd docker && git checkout --quiet tags/"${DOCKER_TAG}" -b "${DOCKER_TAG}" )
339 git clone --quiet https://github.com/saltstack-formulas/locale-formula.git ${F_DIR}/locale
340 ( cd locale && git checkout --quiet tags/"${LOCALE_TAG}" -b "${LOCALE_TAG}" )
343 git clone --quiet https://github.com/saltstack-formulas/nginx-formula.git ${F_DIR}/nginx
344 ( cd nginx && git checkout --quiet tags/"${NGINX_TAG}" -b "${NGINX_TAG}" )
347 git clone --quiet https://github.com/saltstack-formulas/postgres-formula.git ${F_DIR}/postgres
348 ( cd postgres && git checkout --quiet tags/"${POSTGRES_TAG}" -b "${POSTGRES_TAG}" )
350 echo "...letsencrypt"
351 git clone --quiet https://github.com/saltstack-formulas/letsencrypt-formula.git ${F_DIR}/letsencrypt
352 ( cd letsencrypt && git checkout --quiet tags/"${LETSENCRYPT_TAG}" -b "${LETSENCRYPT_TAG}" )
355 git clone --quiet https://git.arvados.org/arvados-formula.git ${F_DIR}/arvados
357 # If we want to try a specific branch of the formula
358 if [ "x${BRANCH}" != "x" ]; then
359 ( cd ${F_DIR}/arvados && git checkout --quiet -t origin/"${BRANCH}" -b "${BRANCH}" )
360 elif [ "x${ARVADOS_TAG}" != "x" ]; then
361 ( cd ${F_DIR}/arvados && git checkout --quiet tags/"${ARVADOS_TAG}" -b "${ARVADOS_TAG}" )
364 if [ "x${VAGRANT}" = "xyes" ]; then
365 EXTRA_STATES_DIR="/home/vagrant/${CONFIG_DIR}/states"
366 SOURCE_PILLARS_DIR="/home/vagrant/${CONFIG_DIR}/pillars"
367 SOURCE_TESTS_DIR="/home/vagrant/${TESTS_DIR}"
369 EXTRA_STATES_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/states"
370 SOURCE_PILLARS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/pillars"
371 SOURCE_TESTS_DIR="${SCRIPT_DIR}/${TESTS_DIR}"
374 SOURCE_STATES_DIR="${EXTRA_STATES_DIR}"
376 echo "Writing pillars and states"
378 # Replace variables (cluster, domain, etc) in the pillars, states and tests
379 # to ease deployment for newcomers
380 if [ ! -d "${SOURCE_PILLARS_DIR}" ]; then
381 echo "${SOURCE_PILLARS_DIR} does not exist or is not a directory. Exiting."
384 for f in $(ls "${SOURCE_PILLARS_DIR}"/*); do
385 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
386 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
387 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
388 s#__CLUSTER__#${CLUSTER}#g;
389 s#__DOMAIN__#${DOMAIN}#g;
390 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
391 s#__IP_INT__#${IP_INT}#g;
392 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
393 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
394 s#__INITIAL_USER__#${INITIAL_USER}#g;
395 s#__LE_AWS_REGION__#${LE_AWS_REGION}#g;
396 s#__LE_AWS_SECRET_ACCESS_KEY__#${LE_AWS_SECRET_ACCESS_KEY}#g;
397 s#__LE_AWS_ACCESS_KEY_ID__#${LE_AWS_ACCESS_KEY_ID}#g;
398 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
399 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
400 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
401 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
402 s#__RELEASE__#${RELEASE}#g;
403 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
404 s#__VERSION__#${VERSION}#g;
405 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
406 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
407 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
408 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
409 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
410 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
411 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
412 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
413 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
414 s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
415 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
416 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
417 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
418 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
419 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
420 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
421 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g" \
422 "${f}" > "${P_DIR}"/$(basename "${f}")
425 if [ ! -d "${SOURCE_TESTS_DIR}" ]; then
426 echo "WARNING: The tests directory was not copied to \"${SOURCE_TESTS_DIR}\"."
427 if [ "x${TEST}" = "xyes" ]; then
428 echo "WARNING: Disabling tests for this installation."
433 # Replace cluster and domain name in the test files
434 for f in $(ls "${SOURCE_TESTS_DIR}"/*); do
435 FILTERS="s#__CLUSTER__#${CLUSTER}#g;
436 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
437 s#__DOMAIN__#${DOMAIN}#g;
438 s#__IP_INT__#${IP_INT}#g;
439 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
440 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g
441 s#__INITIAL_USER__#${INITIAL_USER}#g;
442 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
443 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g"
444 if [ "$USE_SINGLE_HOSTNAME" = "yes" ]; then
445 FILTERS="s#__CLUSTER__.__DOMAIN__#${HOSTNAME_EXT}#g;
449 "${f}" > ${T_DIR}/$(basename "${f}")
451 chmod 755 ${T_DIR}/run-test.sh
454 # Replace helper state files that differ from the formula's examples
455 if [ -d "${SOURCE_STATES_DIR}" ]; then
456 mkdir -p "${F_DIR}"/extra/extra
458 for f in $(ls "${SOURCE_STATES_DIR}"/*); do
459 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
460 s#__CLUSTER__#${CLUSTER}#g;
461 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
462 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
463 s#__DOMAIN__#${DOMAIN}#g;
464 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
465 s#__IP_INT__#${IP_INT}#g;
466 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
467 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
468 s#__INITIAL_USER__#${INITIAL_USER}#g;
469 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
470 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
471 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
472 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
473 s#__RELEASE__#${RELEASE}#g;
474 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
475 s#__VERSION__#${VERSION}#g;
476 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
477 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
478 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
479 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
480 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
481 s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
482 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
483 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
484 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
485 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
486 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
487 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
488 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
489 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
490 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
491 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
492 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g" \
493 "${f}" > "${F_DIR}/extra/extra"/$(basename "${f}")
497 # Now, we build the SALT states/pillars trees
498 # As we need to separate both states and pillars in case we want specific
499 # roles, we iterate on both at the same time
502 cat > ${S_DIR}/top.sls << EOFTSLS
509 cat > ${P_DIR}/top.sls << EOFPSLS
516 # States, extra states
517 if [ -d "${F_DIR}"/extra/extra ]; then
518 SKIP_SNAKE_OIL="snakeoil_certs"
520 if [[ "$DEV_MODE" = "yes" || "${SSL_MODE}" == "self-signed" ]] ; then
521 # In dev mode, we create some snake oil certs that we'll
522 # use as CUSTOM_CERTS, so we don't skip the states file.
523 # Same when using self-signed certificates.
524 SKIP_SNAKE_OIL="dont_add_snakeoil_certs"
526 for f in $(ls "${F_DIR}"/extra/extra/*.sls | egrep -v "${SKIP_SNAKE_OIL}|shell_"); do
527 echo " - extra.$(basename ${f} | sed 's/.sls$//g')" >> ${S_DIR}/top.sls
529 # Use byo or self-signed certificates
530 if [ "${SSL_MODE}" != "lets-encrypt" ]; then
531 mkdir -p "${F_DIR}"/extra/extra/files
535 # If we want specific roles for a node, just add the desired states
536 # and its dependencies
537 if [ -z "${ROLES}" ]; then
539 echo " - nginx.passenger" >> ${S_DIR}/top.sls
540 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
541 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
542 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - extra.aws_credentials" >> ${S_DIR}/top.sls
544 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
546 mkdir -p /srv/salt/certs
547 if [ "${SSL_MODE}" = "bring-your-own" ]; then
548 # Copy certs to formula extra/files
549 cp -rv ${CUSTOM_CERTS_DIR}/* /srv/salt/certs/
550 # We add the custom_certs state
551 grep -q "custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
553 # In self-signed mode, the certificate files will be created and put in the
554 # destination directory by the snakeoil_certs.sls state file
557 echo " - postgres" >> ${S_DIR}/top.sls
558 echo " - docker.software" >> ${S_DIR}/top.sls
559 echo " - arvados" >> ${S_DIR}/top.sls
560 echo " - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
561 echo " - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
562 echo " - extra.passenger_rvm" >> ${S_DIR}/top.sls
565 echo " - docker" >> ${P_DIR}/top.sls
566 echo " - nginx_api_configuration" >> ${P_DIR}/top.sls
567 echo " - nginx_controller_configuration" >> ${P_DIR}/top.sls
568 echo " - nginx_keepproxy_configuration" >> ${P_DIR}/top.sls
569 echo " - nginx_keepweb_configuration" >> ${P_DIR}/top.sls
570 echo " - nginx_passenger" >> ${P_DIR}/top.sls
571 echo " - nginx_websocket_configuration" >> ${P_DIR}/top.sls
572 echo " - nginx_webshell_configuration" >> ${P_DIR}/top.sls
573 echo " - nginx_workbench2_configuration" >> ${P_DIR}/top.sls
574 echo " - nginx_workbench_configuration" >> ${P_DIR}/top.sls
575 echo " - postgresql" >> ${P_DIR}/top.sls
577 # We need to tweak the Nginx's pillar depending whether we want plan nginx or nginx+passenger
578 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
579 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
581 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
582 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
583 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
585 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
587 hosts=("controller" "websocket" "workbench" "workbench2" "webshell" "keepproxy")
588 if [ ${USE_SINGLE_HOSTNAME} = "no" ]; then
589 hosts+=("download" "collections")
594 for c in "${hosts[@]}"; do
595 # Are we in a single-host-single-hostname env?
596 if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
597 # Are we in a single-host-single-hostname env?
598 CERT_NAME=${HOSTNAME_EXT}
600 # We are in a multiple-hostnames env
601 CERT_NAME=${c}.${CLUSTER}.${DOMAIN}
604 # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
605 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${CERT_NAME}*/g;
606 s#__CERT_PEM__#/etc/letsencrypt/live/${CERT_NAME}/fullchain.pem#g;
607 s#__CERT_KEY__#/etc/letsencrypt/live/${CERT_NAME}/privkey.pem#g" \
608 ${P_DIR}/nginx_${c}_configuration.sls
611 # Use custom certs (either dev mode or prod)
612 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
613 # And add the certs in the custom_certs pillar
614 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
615 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
617 for c in controller websocket workbench workbench2 webshell keepweb keepproxy shell; do
618 # Are we in a single-host-single-hostname env?
619 if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
620 # Are we in a single-host-single-hostname env?
621 CERT_NAME=${HOSTNAME_EXT}
623 # We are in a multiple-hostnames env
627 if [[ "$SSL_MODE" == "bring-your-own" ]]; then
628 copy_custom_cert ${CUSTOM_CERTS_DIR} ${CERT_NAME}
631 grep -q ${CERT_NAME} ${P_DIR}/extra_custom_certs.sls || echo " - ${CERT_NAME}" >> ${P_DIR}/extra_custom_certs.sls
633 # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
634 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${CERT_NAME}.pem/g;
635 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${CERT_NAME}.pem#g;
636 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${CERT_NAME}.key#g" \
637 ${P_DIR}/nginx_${c}_configuration.sls
641 # If we add individual roles, make sure we add the repo first
642 echo " - arvados.repo" >> ${S_DIR}/top.sls
643 # We add the extra_custom_certs state
644 grep -q "extra.custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
646 # And we add the basic part for the certs pillar
647 if [ "${SSL_MODE}" != "lets-encrypt" ]; then
648 # And add the certs in the custom_certs pillar
649 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
650 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
651 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
654 for R in ${ROLES}; do
658 echo " - postgres" >> ${S_DIR}/top.sls
660 echo ' - postgresql' >> ${P_DIR}/top.sls
664 # FIXME: https://dev.arvados.org/issues/17352
665 grep -q "postgres.client" ${S_DIR}/top.sls || echo " - postgres.client" >> ${S_DIR}/top.sls
666 if grep -q " - nginx.*$" ${S_DIR}/top.sls; then
667 sed -i s/"^ - nginx.*$"/" - nginx.passenger"/g ${S_DIR}/top.sls
669 echo " - nginx.passenger" >> ${S_DIR}/top.sls
671 echo " - extra.passenger_rvm" >> ${S_DIR}/top.sls
672 ### If we don't install and run LE before arvados-api-server, it fails and breaks everything
673 ### after it. So we add this here as we are, after all, sharing the host for api and controller
674 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
675 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
676 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
678 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
681 if [ "${SSL_MODE}" = "bring-your-own" ]; then
682 copy_custom_cert ${CUSTOM_CERTS_DIR} controller
684 grep -q controller ${P_DIR}/extra_custom_certs.sls || echo " - controller" >> ${P_DIR}/extra_custom_certs.sls
686 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
688 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
689 grep -q "postgresql" ${P_DIR}/top.sls || echo " - postgresql" >> ${P_DIR}/top.sls
690 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
691 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
693 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
694 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
695 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
697 "controller" | "websocket" | "workbench" | "workbench2" | "webshell" | "keepweb" | "keepproxy")
699 if [ "${R}" = "workbench" ]; then
700 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
701 if grep -q " - nginx$" ${S_DIR}/top.sls; then
702 sed -i s/"^ - nginx.*$"/" - nginx.passenger"/g ${S_DIR}/top.sls
704 echo " - nginx.passenger" >> ${S_DIR}/top.sls
707 grep -q "nginx" ${S_DIR}/top.sls || echo " - nginx" >> ${S_DIR}/top.sls
709 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
710 if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
711 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
713 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
715 # Use custom certs, special case for keepweb
716 if [ ${R} = "keepweb" ]; then
717 if [ "${SSL_MODE}" = "bring-your-own" ]; then
718 copy_custom_cert ${CUSTOM_CERTS_DIR} download
719 copy_custom_cert ${CUSTOM_CERTS_DIR} collections
722 if [ "${SSL_MODE}" = "bring-your-own" ]; then
723 copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
727 # webshell role is just a nginx vhost, so it has no state
728 if [ "${R}" != "webshell" ]; then
729 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
732 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
733 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
734 # Special case for keepweb
735 if [ ${R} = "keepweb" ]; then
736 grep -q "nginx_download_configuration" ${P_DIR}/top.sls || echo " - nginx_download_configuration" >> ${P_DIR}/top.sls
737 grep -q "nginx_collections_configuration" ${P_DIR}/top.sls || echo " - nginx_collections_configuration" >> ${P_DIR}/top.sls
740 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
741 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
742 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
744 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
745 grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
747 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
748 # Special case for keepweb
749 if [ ${R} = "keepweb" ]; then
750 for kwsub in download collections; do
751 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${kwsub}.${CLUSTER}.${DOMAIN}*/g;
752 s#__CERT_PEM__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
753 s#__CERT_KEY__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
754 ${P_DIR}/nginx_${kwsub}_configuration.sls
757 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${R}.${CLUSTER}.${DOMAIN}*/g;
758 s#__CERT_PEM__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
759 s#__CERT_KEY__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
760 ${P_DIR}/nginx_${R}_configuration.sls
763 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
764 # Special case for keepweb
765 if [ ${R} = "keepweb" ]; then
766 for kwsub in download collections; do
767 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${kwsub}.pem/g;
768 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${kwsub}.pem#g;
769 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${kwsub}.key#g" \
770 ${P_DIR}/nginx_${kwsub}_configuration.sls
771 grep -q ${kwsub} ${P_DIR}/extra_custom_certs.sls || echo " - ${kwsub}" >> ${P_DIR}/extra_custom_certs.sls
774 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
775 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
776 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
777 ${P_DIR}/nginx_${R}_configuration.sls
778 grep -q ${R} ${P_DIR}/extra_custom_certs.sls || echo " - ${R}" >> ${P_DIR}/extra_custom_certs.sls
781 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
782 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
786 echo " - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
787 echo " - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
788 grep -q "docker" ${S_DIR}/top.sls || echo " - docker.software" >> ${S_DIR}/top.sls
789 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
791 grep -q "docker" ${P_DIR}/top.sls || echo " - docker" >> ${P_DIR}/top.sls
793 "dispatcher" | "keepbalance" | "keepstore")
795 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
797 # ATM, no specific pillar needed
800 echo "Unknown role ${R}"
807 if [ "${DUMP_CONFIG}" = "yes" ]; then
808 # We won't run the rest of the script because we're just dumping the config
812 # Now run the install
813 salt-call --local state.apply -l ${LOG_LEVEL}
815 # Finally, make sure that /etc/hosts is not overwritten on reboot
816 if [ -d /etc/cloud/cloud.cfg.d ]; then
817 # TODO: will this work on CentOS?
818 sed -i 's/^manage_etc_hosts: true/#manage_etc_hosts: true/g' /etc/cloud/cloud.cfg.d/*
821 # Leave a copy of the Arvados CA so the user can copy it where it's required
822 if [ "$DEV_MODE" = "yes" ]; then
823 echo "Copying the Arvados CA certificate to the installer dir, so you can import it"
824 # If running in a vagrant VM, also add default user to docker group
825 if [ "x${VAGRANT}" = "xyes" ]; then
826 cp /etc/ssl/certs/arvados-snakeoil-ca.pem /vagrant/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
828 echo "Adding the vagrant user to the docker group"
829 usermod -a -G docker vagrant
831 cp /etc/ssl/certs/arvados-snakeoil-ca.pem ${SCRIPT_DIR}/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
835 # Test that the installation finished correctly
836 if [ "x${TEST}" = "xyes" ]; then
838 # If we use RVM, we need to run this with it, or most ruby commands will fail
840 if [ -x /usr/local/rvm/bin/rvm-exec ]; then
841 RVM_EXEC="/usr/local/rvm/bin/rvm-exec"
843 ${RVM_EXEC} ./run-test.sh