#!/bin/bash set -eu -o pipefail readonly DATA_DIR="/home/yellowtent/data" script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${script_dir}/../INFRA_VERSION" # this injects INFRA_VERSION arg_fqdn="$1" # removing containers ensures containers are launched with latest config updates # restore code in appatask does not delete old containers infra_version="none" [[ -f "${DATA_DIR}/INFRA_VERSION" ]] && infra_version=$(cat "${DATA_DIR}/INFRA_VERSION") if [[ "${infra_version}" == "${INFRA_VERSION}" ]]; then echo "Infrastructure is upto date" exit 0 fi echo "Upgrading infrastructure from ${infra_version} to ${INFRA_VERSION}" existing_containers=$(docker ps -qa) echo "Remove containers: ${existing_containers}" if [[ -n "${existing_containers}" ]]; then echo "${existing_containers}" | xargs docker rm -f fi # graphite graphite_container_id=$(docker run --restart=always -d --name="graphite" \ -m 75m \ --memory-swap 150m \ -p 127.0.0.1:2003:2003 \ -p 127.0.0.1:2004:2004 \ -p 127.0.0.1:8000:8000 \ -v "${DATA_DIR}/graphite:/app/data" \ --read-only -v /tmp -v /run \ "${GRAPHITE_IMAGE}") echo "Graphite container id: ${graphite_container_id}" if docker images "${GRAPHITE_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${GRAPHITE_IMAGE}" | xargs --no-run-if-empty docker rmi; then echo "Removed old graphite images" fi # mail (MAIL_SMTP_PORT is 2500 in addons.js. used in mailer.js as well) mail_container_id=$(docker run --restart=always -d --name="mail" \ -m 75m \ --memory-swap 150m \ -h "${arg_fqdn}" \ -e "DOMAIN_NAME=${arg_fqdn}" \ -v "${DATA_DIR}/box/mail:/app/data" \ --read-only -v /tmp -v /run \ "${MAIL_IMAGE}") echo "Mail container id: ${mail_container_id}" if docker images "${MAIL_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${MAIL_IMAGE}" | xargs --no-run-if-empty docker rmi; then echo "Removed old mail images" fi # mysql mysql_addon_root_password=$(pwgen -1 -s) docker0_ip=$(/sbin/ifconfig docker0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}') cat > "${DATA_DIR}/addons/mysql_vars.sh" < "${DATA_DIR}/addons/postgresql_vars.sh" < "${DATA_DIR}/addons/mongodb_vars.sh" < "${DATA_DIR}/INFRA_VERSION"