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 # We pin the salt version to avoid potential incompatibilities when a new
210 # stable version is released.
213 # Other formula versions we depend on
214 POSTGRES_TAG="v0.44.0"
218 LETSENCRYPT_TAG="v2.1.0"
219 LOGROTATE_TAG="v0.14.0"
222 DUMP_SALT_CONFIG_DIR=""
226 F_DIR="/srv/formulas"
230 T_DIR="/tmp/cluster_tests"
236 if [ -s ${CONFIG_FILE} ]; then
237 source ${CONFIG_FILE}
239 echo >&2 "You don't seem to have a config file with initial values."
240 echo >&2 "Please create a '${CONFIG_FILE}' file as described in"
241 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
242 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
246 if [ ! -d ${CONFIG_DIR} ]; then
247 echo >&2 "You don't seem to have a config directory with pillars and states."
248 echo >&2 "Please create a '${CONFIG_DIR}' directory (as configured in your '${CONFIG_FILE}'). Please see"
249 echo >&2 " * https://doc.arvados.org/install/salt-single-host.html#single_host, or"
250 echo >&2 " * https://doc.arvados.org/install/salt-multi-host.html#multi_host_multi_hostnames"
254 if grep -rni 'fixme' ${CONFIG_FILE} ${CONFIG_DIR} ; then
255 echo >&2 "The config file ${CONFIG_FILE} has some parameters that need to be modified."
256 echo >&2 "Please, fix them and re-run the provision script."
260 if ! grep -qE '^[[:alnum:]]{5}$' <<<${CLUSTER} ; then
261 echo >&2 "ERROR: <CLUSTER> must be exactly 5 lowercase alphanumeric characters long"
262 echo >&2 "Fix the cluster name in the 'local.params' file and re-run the provision script"
266 # Only used in single_host/single_name deploys
267 if [ ! -z "${HOSTNAME_EXT}" ] ; then
268 # We need to add some extra control vars to manage a single certificate vs. multiple
269 USE_SINGLE_HOSTNAME="yes"
270 # Make sure that the value configured as IP_INT is a real IP on the system.
271 # If we don't error out early here when there is a mismatch, the formula will
272 # fail with hard to interpret nginx errors later on.
273 ip addr list |grep "${IP_INT}/" >/dev/null
274 if [[ $? -ne 0 ]]; then
275 echo "Unable to find the IP_INT address '${IP_INT}' on the system, please correct the value in local.params. Exiting..."
279 USE_SINGLE_HOSTNAME="no"
280 # We set this variable, anyway, so sed lines do not fail and we don't need to add more
282 HOSTNAME_EXT="${CLUSTER}.${DOMAIN}"
285 if [ "${DUMP_CONFIG}" = "yes" ]; then
286 echo "The provision installer will just dump a config under ${DUMP_SALT_CONFIG_DIR} and exit"
288 # Install a few dependency packages
289 # First, let's figure out the OS we're working on
290 OS_ID=$(grep ^ID= /etc/os-release |cut -f 2 -d= |cut -f 2 -d \")
291 echo "Detected distro: ${OS_ID}"
295 echo "WARNING! Disabling SELinux, see https://dev.arvados.org/issues/18019"
296 sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
297 setenforce permissive
298 yum install -y curl git jq
301 # Wait 2 minutes for any apt locks to clear
302 # This option is supported from apt 1.9.1 and ignored in older apt versions.
303 # Cf. https://blog.sinjakli.co.uk/2021/10/25/waiting-for-apt-locks-without-the-hacky-bash-scripts/
304 DEBIAN_FRONTEND=noninteractive apt -o DPkg::Lock::Timeout=120 update
305 DEBIAN_FRONTEND=noninteractive apt install -y curl git jq
309 if which salt-call; then
310 echo "Salt already installed"
312 curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
313 sh /tmp/bootstrap_salt.sh -XdfP -x python3 stable ${SALT_VERSION}
314 /bin/systemctl stop salt-minion.service
315 /bin/systemctl disable salt-minion.service
318 # Set salt to masterless mode
319 cat > /etc/salt/minion << EOFSM
334 mkdir -p ${S_DIR} ${F_DIR} ${P_DIR} ${T_DIR}
336 # Get the formula and dependencies
337 cd ${F_DIR} || exit 1
338 echo "Cloning formulas"
339 test -d docker && ( cd docker && git fetch ) \
340 || git clone --quiet https://github.com/saltstack-formulas/docker-formula.git ${F_DIR}/docker
341 ( cd docker && git checkout --quiet tags/"${DOCKER_TAG}" )
344 test -d locale && ( cd locale && git fetch ) \
345 || git clone --quiet https://github.com/saltstack-formulas/locale-formula.git ${F_DIR}/locale
346 ( cd locale && git checkout --quiet tags/"${LOCALE_TAG}" )
349 test -d nginx && ( cd nginx && git fetch ) \
350 || git clone --quiet https://github.com/saltstack-formulas/nginx-formula.git ${F_DIR}/nginx
351 ( cd nginx && git checkout --quiet tags/"${NGINX_TAG}" )
354 test -d postgres && ( cd postgres && git fetch ) \
355 || git clone --quiet https://github.com/saltstack-formulas/postgres-formula.git ${F_DIR}/postgres
356 ( cd postgres && git checkout --quiet tags/"${POSTGRES_TAG}" )
358 echo "...letsencrypt"
359 test -d letsencrypt && ( cd letsencrypt && git fetch ) \
360 || git clone --quiet https://github.com/saltstack-formulas/letsencrypt-formula.git ${F_DIR}/letsencrypt
361 ( cd letsencrypt && git checkout --quiet tags/"${LETSENCRYPT_TAG}" )
364 test -d logrotate && ( cd logrotate && git fetch ) \
365 || git clone --quiet https://github.com/saltstack-formulas/logrotate-formula.git ${F_DIR}/logrotate
366 ( cd logrotate && git checkout --quiet tags/"${LOGROTATE_TAG}" )
369 test -d arvados || git clone --quiet https://git.arvados.org/arvados-formula.git ${F_DIR}/arvados
371 # If we want to try a specific branch of the formula
372 if [ "x${BRANCH}" != "x" ]; then
373 ( cd ${F_DIR}/arvados && git checkout --quiet -t origin/"${BRANCH}" -b "${BRANCH}" )
374 elif [ "x${ARVADOS_TAG}" != "x" ]; then
375 ( cd ${F_DIR}/arvados && git checkout --quiet tags/"${ARVADOS_TAG}" -b "${ARVADOS_TAG}" )
378 if [ "x${VAGRANT}" = "xyes" ]; then
379 EXTRA_STATES_DIR="/home/vagrant/${CONFIG_DIR}/states"
380 SOURCE_PILLARS_DIR="/home/vagrant/${CONFIG_DIR}/pillars"
381 SOURCE_TESTS_DIR="/home/vagrant/${TESTS_DIR}"
383 EXTRA_STATES_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/states"
384 SOURCE_PILLARS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}/pillars"
385 SOURCE_TESTS_DIR="${SCRIPT_DIR}/${TESTS_DIR}"
388 SOURCE_STATES_DIR="${EXTRA_STATES_DIR}"
390 echo "Writing pillars and states"
392 # Replace variables (cluster, domain, etc) in the pillars, states and tests
393 # to ease deployment for newcomers
394 if [ ! -d "${SOURCE_PILLARS_DIR}" ]; then
395 echo "${SOURCE_PILLARS_DIR} does not exist or is not a directory. Exiting."
398 for f in $(ls "${SOURCE_PILLARS_DIR}"/*); do
399 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
400 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
401 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
402 s#__CLUSTER__#${CLUSTER}#g;
403 s#__DOMAIN__#${DOMAIN}#g;
404 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
405 s#__IP_INT__#${IP_INT}#g;
406 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
407 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
408 s#__INITIAL_USER__#${INITIAL_USER}#g;
409 s#__LE_AWS_REGION__#${LE_AWS_REGION}#g;
410 s#__LE_AWS_SECRET_ACCESS_KEY__#${LE_AWS_SECRET_ACCESS_KEY}#g;
411 s#__LE_AWS_ACCESS_KEY_ID__#${LE_AWS_ACCESS_KEY_ID}#g;
412 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
413 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
414 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
415 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
416 s#__RELEASE__#${RELEASE}#g;
417 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
418 s#__VERSION__#${VERSION}#g;
419 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
420 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
421 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
422 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
423 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
424 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
425 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
426 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
427 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
428 s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
429 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
430 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
431 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
432 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
433 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
434 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
435 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g" \
436 "${f}" > "${P_DIR}"/$(basename "${f}")
439 if [ ! -d "${SOURCE_TESTS_DIR}" ]; then
440 echo "WARNING: The tests directory was not copied to \"${SOURCE_TESTS_DIR}\"."
441 if [ "x${TEST}" = "xyes" ]; then
442 echo "WARNING: Disabling tests for this installation."
447 # Replace cluster and domain name in the test files
448 for f in $(ls "${SOURCE_TESTS_DIR}"/*); do
449 FILTERS="s#__CLUSTER__#${CLUSTER}#g;
450 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
451 s#__DOMAIN__#${DOMAIN}#g;
452 s#__IP_INT__#${IP_INT}#g;
453 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
454 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g
455 s#__INITIAL_USER__#${INITIAL_USER}#g;
456 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
457 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g"
458 if [ "$USE_SINGLE_HOSTNAME" = "yes" ]; then
459 FILTERS="s#__CLUSTER__.__DOMAIN__#${HOSTNAME_EXT}#g;
463 "${f}" > ${T_DIR}/$(basename "${f}")
465 chmod 755 ${T_DIR}/run-test.sh
468 # Replace helper state files that differ from the formula's examples
469 if [ -d "${SOURCE_STATES_DIR}" ]; then
470 mkdir -p "${F_DIR}"/extra/extra
472 for f in $(ls "${SOURCE_STATES_DIR}"/*); do
473 sed "s#__ANONYMOUS_USER_TOKEN__#${ANONYMOUS_USER_TOKEN}#g;
474 s#__CLUSTER__#${CLUSTER}#g;
475 s#__BLOB_SIGNING_KEY__#${BLOB_SIGNING_KEY}#g;
476 s#__CONTROLLER_EXT_SSL_PORT__#${CONTROLLER_EXT_SSL_PORT}#g;
477 s#__DOMAIN__#${DOMAIN}#g;
478 s#__HOSTNAME_EXT__#${HOSTNAME_EXT}#g;
479 s#__IP_INT__#${IP_INT}#g;
480 s#__INITIAL_USER_EMAIL__#${INITIAL_USER_EMAIL}#g;
481 s#__INITIAL_USER_PASSWORD__#${INITIAL_USER_PASSWORD}#g;
482 s#__INITIAL_USER__#${INITIAL_USER}#g;
483 s#__DATABASE_PASSWORD__#${DATABASE_PASSWORD}#g;
484 s#__KEEPWEB_EXT_SSL_PORT__#${KEEPWEB_EXT_SSL_PORT}#g;
485 s#__KEEP_EXT_SSL_PORT__#${KEEP_EXT_SSL_PORT}#g;
486 s#__MANAGEMENT_TOKEN__#${MANAGEMENT_TOKEN}#g;
487 s#__RELEASE__#${RELEASE}#g;
488 s#__SYSTEM_ROOT_TOKEN__#${SYSTEM_ROOT_TOKEN}#g;
489 s#__VERSION__#${VERSION}#g;
490 s#__CLUSTER_INT_CIDR__#${CLUSTER_INT_CIDR}#g;
491 s#__CONTROLLER_INT_IP__#${CONTROLLER_INT_IP}#g;
492 s#__WEBSOCKET_INT_IP__#${WEBSOCKET_INT_IP}#g;
493 s#__KEEP_INT_IP__#${KEEP_INT_IP}#g;
494 s#__KEEPSTORE0_INT_IP__#${KEEPSTORE0_INT_IP}#g;
495 s#__KEEPSTORE1_INT_IP__#${KEEPSTORE1_INT_IP}#g;
496 s#__KEEPWEB_INT_IP__#${KEEPWEB_INT_IP}#g;
497 s#__WEBSHELL_INT_IP__#${WEBSHELL_INT_IP}#g;
498 s#__WORKBENCH1_INT_IP__#${WORKBENCH1_INT_IP}#g;
499 s#__WORKBENCH2_INT_IP__#${WORKBENCH2_INT_IP}#g;
500 s#__DATABASE_INT_IP__#${DATABASE_INT_IP}#g;
501 s#__WEBSHELL_EXT_SSL_PORT__#${WEBSHELL_EXT_SSL_PORT}#g;
502 s#__SHELL_INT_IP__#${SHELL_INT_IP}#g;
503 s#__WEBSOCKET_EXT_SSL_PORT__#${WEBSOCKET_EXT_SSL_PORT}#g;
504 s#__WORKBENCH1_EXT_SSL_PORT__#${WORKBENCH1_EXT_SSL_PORT}#g;
505 s#__WORKBENCH2_EXT_SSL_PORT__#${WORKBENCH2_EXT_SSL_PORT}#g;
506 s#__WORKBENCH_SECRET_KEY__#${WORKBENCH_SECRET_KEY}#g" \
507 "${f}" > "${F_DIR}/extra/extra"/$(basename "${f}")
511 # Now, we build the SALT states/pillars trees
512 # As we need to separate both states and pillars in case we want specific
513 # roles, we iterate on both at the same time
516 cat > ${S_DIR}/top.sls << EOFTSLS
523 cat > ${P_DIR}/top.sls << EOFPSLS
530 # States, extra states
531 if [ -d "${F_DIR}"/extra/extra ]; then
532 SKIP_SNAKE_OIL="snakeoil_certs"
534 if [[ "$DEV_MODE" = "yes" || "${SSL_MODE}" == "self-signed" ]] ; then
535 # In dev mode, we create some snake oil certs that we'll
536 # use as CUSTOM_CERTS, so we don't skip the states file.
537 # Same when using self-signed certificates.
538 SKIP_SNAKE_OIL="dont_add_snakeoil_certs"
540 for f in $(ls "${F_DIR}"/extra/extra/*.sls | egrep -v "${SKIP_SNAKE_OIL}|shell_"); do
541 echo " - extra.$(basename ${f} | sed 's/.sls$//g')" >> ${S_DIR}/top.sls
543 # Use byo or self-signed certificates
544 if [ "${SSL_MODE}" != "lets-encrypt" ]; then
545 mkdir -p "${F_DIR}"/extra/extra/files
549 # If we want specific roles for a node, just add the desired states
550 # and its dependencies
551 if [ -z "${ROLES}" ]; then
553 echo " - nginx.passenger" >> ${S_DIR}/top.sls
554 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
555 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
556 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - extra.aws_credentials" >> ${S_DIR}/top.sls
558 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
560 mkdir -p /srv/salt/certs
561 if [ "${SSL_MODE}" = "bring-your-own" ]; then
562 # Copy certs to formula extra/files
563 cp -rv ${CUSTOM_CERTS_DIR}/* /srv/salt/certs/
564 # We add the custom_certs state
565 grep -q "custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
567 # In self-signed mode, the certificate files will be created and put in the
568 # destination directory by the snakeoil_certs.sls state file
571 echo " - postgres" >> ${S_DIR}/top.sls
572 echo " - logrotate" >> ${S_DIR}/top.sls
573 echo " - docker.software" >> ${S_DIR}/top.sls
574 echo " - arvados" >> ${S_DIR}/top.sls
575 echo " - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
576 echo " - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
577 echo " - extra.passenger_rvm" >> ${S_DIR}/top.sls
580 echo " - docker" >> ${P_DIR}/top.sls
581 echo " - nginx_api_configuration" >> ${P_DIR}/top.sls
582 echo " - logrotate_api" >> ${P_DIR}/top.sls
583 echo " - nginx_controller_configuration" >> ${P_DIR}/top.sls
584 echo " - nginx_keepproxy_configuration" >> ${P_DIR}/top.sls
585 echo " - nginx_keepweb_configuration" >> ${P_DIR}/top.sls
586 echo " - nginx_passenger" >> ${P_DIR}/top.sls
587 echo " - nginx_websocket_configuration" >> ${P_DIR}/top.sls
588 echo " - nginx_webshell_configuration" >> ${P_DIR}/top.sls
589 echo " - nginx_workbench2_configuration" >> ${P_DIR}/top.sls
590 echo " - nginx_workbench_configuration" >> ${P_DIR}/top.sls
591 echo " - logrotate_wb1" >> ${P_DIR}/top.sls
592 echo " - postgresql" >> ${P_DIR}/top.sls
594 # We need to tweak the Nginx's pillar depending whether we want plan nginx or nginx+passenger
595 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
596 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
598 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
599 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
600 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
602 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
604 hosts=("controller" "websocket" "workbench" "workbench2" "webshell" "keepproxy")
605 if [ ${USE_SINGLE_HOSTNAME} = "no" ]; then
606 hosts+=("download" "collections")
611 for c in "${hosts[@]}"; do
612 # Are we in a single-host-single-hostname env?
613 if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
614 # Are we in a single-host-single-hostname env?
615 CERT_NAME=${HOSTNAME_EXT}
617 # We are in a multiple-hostnames env
618 CERT_NAME=${c}.${CLUSTER}.${DOMAIN}
621 # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
622 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${CERT_NAME}*/g;
623 s#__CERT_PEM__#/etc/letsencrypt/live/${CERT_NAME}/fullchain.pem#g;
624 s#__CERT_KEY__#/etc/letsencrypt/live/${CERT_NAME}/privkey.pem#g" \
625 ${P_DIR}/nginx_${c}_configuration.sls
628 # Use custom certs (either dev mode or prod)
629 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
630 # And add the certs in the custom_certs pillar
631 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
632 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
634 for c in controller websocket workbench workbench2 webshell keepweb keepproxy shell; do
635 # Are we in a single-host-single-hostname env?
636 if [ "${USE_SINGLE_HOSTNAME}" = "yes" ]; then
637 # Are we in a single-host-single-hostname env?
638 CERT_NAME=${HOSTNAME_EXT}
640 # We are in a multiple-hostnames env
644 if [[ "$SSL_MODE" == "bring-your-own" ]]; then
645 copy_custom_cert ${CUSTOM_CERTS_DIR} ${CERT_NAME}
648 grep -q ${CERT_NAME} ${P_DIR}/extra_custom_certs.sls || echo " - ${CERT_NAME}" >> ${P_DIR}/extra_custom_certs.sls
650 # As the pillar differs whether we use LE or custom certs, we need to do a final edition on them
651 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${CERT_NAME}.pem/g;
652 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${CERT_NAME}.pem#g;
653 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${CERT_NAME}.key#g" \
654 ${P_DIR}/nginx_${c}_configuration.sls
658 # If we add individual roles, make sure we add the repo first
659 echo " - arvados.repo" >> ${S_DIR}/top.sls
660 # We add the extra_custom_certs state
661 grep -q "extra.custom_certs" ${S_DIR}/top.sls || echo " - extra.custom_certs" >> ${S_DIR}/top.sls
663 # And we add the basic part for the certs pillar
664 if [ "${SSL_MODE}" != "lets-encrypt" ]; then
665 # And add the certs in the custom_certs pillar
666 echo "extra_custom_certs_dir: /srv/salt/certs" > ${P_DIR}/extra_custom_certs.sls
667 echo "extra_custom_certs:" >> ${P_DIR}/extra_custom_certs.sls
668 grep -q "extra_custom_certs" ${P_DIR}/top.sls || echo " - extra_custom_certs" >> ${P_DIR}/top.sls
671 for R in ${ROLES}; do
675 echo " - postgres" >> ${S_DIR}/top.sls
677 echo ' - postgresql' >> ${P_DIR}/top.sls
681 grep -q " - logrotate" ${S_DIR}/top.sls || echo " - logrotate" >> ${S_DIR}/top.sls
682 if grep -q " - nginx.*$" ${S_DIR}/top.sls; then
683 sed -i s/"^ - nginx.*$"/" - nginx.passenger"/g ${S_DIR}/top.sls
685 echo " - nginx.passenger" >> ${S_DIR}/top.sls
687 echo " - extra.passenger_rvm" >> ${S_DIR}/top.sls
688 ### If we don't install and run LE before arvados-api-server, it fails and breaks everything
689 ### after it. So we add this here as we are, after all, sharing the host for api and controller
690 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
691 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
692 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
694 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
697 if [ "${SSL_MODE}" = "bring-your-own" ]; then
698 copy_custom_cert ${CUSTOM_CERTS_DIR} controller
700 grep -q controller ${P_DIR}/extra_custom_certs.sls || echo " - controller" >> ${P_DIR}/extra_custom_certs.sls
702 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
704 grep -q "logrotate_api" ${P_DIR}/top.sls || echo " - logrotate_api" >> ${P_DIR}/top.sls
705 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
706 grep -q "postgresql" ${P_DIR}/top.sls || echo " - postgresql" >> ${P_DIR}/top.sls
707 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
708 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
710 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
711 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
712 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
714 "controller" | "websocket" | "workbench" | "workbench2" | "webshell" | "keepweb" | "keepproxy")
716 if [ "${R}" = "workbench" ]; then
717 grep -q " - logrotate" ${S_DIR}/top.sls || echo " - logrotate" >> ${S_DIR}/top.sls
718 NGINX_INSTALL_SOURCE="install_from_phusionpassenger"
719 if grep -q " - nginx$" ${S_DIR}/top.sls; then
720 sed -i s/"^ - nginx.*$"/" - nginx.passenger"/g ${S_DIR}/top.sls
722 echo " - nginx.passenger" >> ${S_DIR}/top.sls
725 grep -q "nginx" ${S_DIR}/top.sls || echo " - nginx" >> ${S_DIR}/top.sls
727 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
728 if [ "x${USE_LETSENCRYPT_ROUTE53}" = "xyes" ]; then
729 grep -q "aws_credentials" ${S_DIR}/top.sls || echo " - aws_credentials" >> ${S_DIR}/top.sls
731 grep -q "letsencrypt" ${S_DIR}/top.sls || echo " - letsencrypt" >> ${S_DIR}/top.sls
733 # Use custom certs, special case for keepweb
734 if [ ${R} = "keepweb" ]; then
735 if [ "${SSL_MODE}" = "bring-your-own" ]; then
736 copy_custom_cert ${CUSTOM_CERTS_DIR} download
737 copy_custom_cert ${CUSTOM_CERTS_DIR} collections
740 if [ "${SSL_MODE}" = "bring-your-own" ]; then
741 copy_custom_cert ${CUSTOM_CERTS_DIR} ${R}
745 # webshell role is just a nginx vhost, so it has no state
746 if [ "${R}" != "webshell" ]; then
747 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
750 if [ "${R}" = "workbench" ]; then
751 grep -q "logrotate_wb1" ${P_DIR}/top.sls || echo " - logrotate_wb1" >> ${P_DIR}/top.sls
753 grep -q "nginx_passenger" ${P_DIR}/top.sls || echo " - nginx_passenger" >> ${P_DIR}/top.sls
754 grep -q "nginx_${R}_configuration" ${P_DIR}/top.sls || echo " - nginx_${R}_configuration" >> ${P_DIR}/top.sls
755 # Special case for keepweb
756 if [ ${R} = "keepweb" ]; then
757 grep -q "nginx_download_configuration" ${P_DIR}/top.sls || echo " - nginx_download_configuration" >> ${P_DIR}/top.sls
758 grep -q "nginx_collections_configuration" ${P_DIR}/top.sls || echo " - nginx_collections_configuration" >> ${P_DIR}/top.sls
761 if [ "${SSL_MODE}" = "lets-encrypt" ]; then
762 if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then
763 grep -q "aws_credentials" ${P_DIR}/top.sls || echo " - aws_credentials" >> ${P_DIR}/top.sls
765 grep -q "letsencrypt" ${P_DIR}/top.sls || echo " - letsencrypt" >> ${P_DIR}/top.sls
766 grep -q "letsencrypt_${R}_configuration" ${P_DIR}/top.sls || echo " - letsencrypt_${R}_configuration" >> ${P_DIR}/top.sls
768 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
769 # Special case for keepweb
770 if [ ${R} = "keepweb" ]; then
771 for kwsub in download collections; do
772 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${kwsub}.${CLUSTER}.${DOMAIN}*/g;
773 s#__CERT_PEM__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
774 s#__CERT_KEY__#/etc/letsencrypt/live/${kwsub}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
775 ${P_DIR}/nginx_${kwsub}_configuration.sls
778 sed -i "s/__CERT_REQUIRES__/cmd: create-initial-cert-${R}.${CLUSTER}.${DOMAIN}*/g;
779 s#__CERT_PEM__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/fullchain.pem#g;
780 s#__CERT_KEY__#/etc/letsencrypt/live/${R}.${CLUSTER}.${DOMAIN}/privkey.pem#g" \
781 ${P_DIR}/nginx_${R}_configuration.sls
784 # As the pillar differ whether we use LE or custom certs, we need to do a final edition on them
785 # Special case for keepweb
786 if [ ${R} = "keepweb" ]; then
787 for kwsub in download collections; do
788 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${kwsub}.pem/g;
789 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${kwsub}.pem#g;
790 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${kwsub}.key#g" \
791 ${P_DIR}/nginx_${kwsub}_configuration.sls
792 grep -q ${kwsub} ${P_DIR}/extra_custom_certs.sls || echo " - ${kwsub}" >> ${P_DIR}/extra_custom_certs.sls
795 sed -i "s/__CERT_REQUIRES__/file: extra_custom_certs_file_copy_arvados-${R}.pem/g;
796 s#__CERT_PEM__#/etc/nginx/ssl/arvados-${R}.pem#g;
797 s#__CERT_KEY__#/etc/nginx/ssl/arvados-${R}.key#g" \
798 ${P_DIR}/nginx_${R}_configuration.sls
799 grep -q ${R} ${P_DIR}/extra_custom_certs.sls || echo " - ${R}" >> ${P_DIR}/extra_custom_certs.sls
802 # We need to tweak the Nginx's pillar depending whether we want plain nginx or nginx+passenger
803 sed -i "s/__NGINX_INSTALL_SOURCE__/${NGINX_INSTALL_SOURCE}/g" ${P_DIR}/nginx_passenger.sls
807 echo " - extra.shell_sudo_passwordless" >> ${S_DIR}/top.sls
808 echo " - extra.shell_cron_add_login_sync" >> ${S_DIR}/top.sls
809 grep -q "docker" ${S_DIR}/top.sls || echo " - docker.software" >> ${S_DIR}/top.sls
810 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
812 grep -q "docker" ${P_DIR}/top.sls || echo " - docker" >> ${P_DIR}/top.sls
814 "dispatcher" | "keepbalance" | "keepstore")
816 grep -q "arvados.${R}" ${S_DIR}/top.sls || echo " - arvados.${R}" >> ${S_DIR}/top.sls
818 # ATM, no specific pillar needed
821 echo "Unknown role ${R}"
828 if [ "${DUMP_CONFIG}" = "yes" ]; then
829 # We won't run the rest of the script because we're just dumping the config
833 # Now run the install
834 salt-call --local state.apply -l ${LOG_LEVEL}
836 # Finally, make sure that /etc/hosts is not overwritten on reboot
837 if [ -d /etc/cloud/cloud.cfg.d ]; then
838 # TODO: will this work on CentOS?
839 sed -i 's/^manage_etc_hosts: true/#manage_etc_hosts: true/g' /etc/cloud/cloud.cfg.d/*
842 # Leave a copy of the Arvados CA so the user can copy it where it's required
843 if [ "$DEV_MODE" = "yes" ]; then
844 echo "Copying the Arvados CA certificate to the installer dir, so you can import it"
845 # If running in a vagrant VM, also add default user to docker group
846 if [ "x${VAGRANT}" = "xyes" ]; then
847 cp /etc/ssl/certs/arvados-snakeoil-ca.pem /vagrant/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
849 echo "Adding the vagrant user to the docker group"
850 usermod -a -G docker vagrant
852 cp /etc/ssl/certs/arvados-snakeoil-ca.pem ${SCRIPT_DIR}/${CLUSTER}.${DOMAIN}-arvados-snakeoil-ca.pem
856 # Test that the installation finished correctly
857 if [ "x${TEST}" = "xyes" ]; then
859 # If we use RVM, we need to run this with it, or most ruby commands will fail
861 if [ -x /usr/local/rvm/bin/rvm-exec ]; then
862 RVM_EXEC="/usr/local/rvm/bin/rvm-exec"
864 ${RVM_EXEC} ./run-test.sh