#!/bin/bash set -e # Synchrony startup wrapper for systemd. Note: This expects the # environment to be setup, usually by sourceing /etc/atl and # /etc/atl.synchrony with EnvironmentFile. See the rest of this role # for details. The rest of the variables below need to be calculated # at runtime. # Find the first Postgres driver in lib folder SYNCHRONY_JWT_PRIVATE_KEY="UNSET" SYNCHRONY_JWT_PUBLIC_KEY="UNSET" ATL_POSTGRES_DRIVER_PATH=$(ls -t ${ATL_CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/lib/postgresql*.jar | head -n 1) SYNCHRONY_CLASSPATH="${ATL_SYNCHRONY_JAR_PATH}:${ATL_POSTGRES_DRIVER_PATH}" # To support retries these commands won't fail the script by virtue of using `--shell` option for xmllint. function extractJWTKeyFromConfluenceConfig { local keyType=$1 if [[ "${keyType}" != "jwt.private.key" && "${keyType}" != "jwt.public.key" ]]; then atl_log "Unexpected value for keyType - ${keyType} to extract JWT key from confluence.cfg.xml" exit 1 fi echo "cat //properties/property[@name='${keyType}']/text()" | xmllint --nocdata --shell ${ATL_CONFLUENCE_SHARED_CONFIG_FILE} | sed '1d;$d' } # Synchrony requires JWT keys to communicate with Confluence application. These keys are written to the config file # after admin will go through the setup and provide license. This function waits for the keys being available in the # config file. function waitForConfluenceConfigInSharedHome() { atl_log "=== BEGIN: Waiting for confluence.cfg.xml available in shared home folder ===" while [[ ! -f ${ATL_CONFLUENCE_SHARED_CONFIG_FILE} ]]; do sleep ${ATL_SYNCHRONY_WAITING_CONFIG_TIME} atl_log "====== : Keep waiting for ${ATL_SYNCHRONY_WAITING_CONFIG_TIME} seconds ======" done atl_log "====== : Fetching JWT keys from Confluence config... ======" while [[ -z ${SYNCHRONY_JWT_PRIVATE_KEY} || -z ${SYNCHRONY_JWT_PUBLIC_KEY} ]]; do SYNCHRONY_JWT_PRIVATE_KEY=$(extractJWTKeyFromConfluenceConfig 'jwt.private.key') >> ${ATL_LOG} 2>&1 SYNCHRONY_JWT_PUBLIC_KEY=$(extractJWTKeyFromConfluenceConfig 'jwt.public.key') >> ${ATL_LOG} 2>&1 if [[ -z ${SYNCHRONY_JWT_PRIVATE_KEY} || -z ${SYNCHRONY_JWT_PUBLIC_KEY} ]]; then atl_log "====== : Could not load value for JWT key; will wait for next ${ATL_SYNCHRONY_WAITING_CONFIG_TIME} seconds before reload ======" sleep ${ATL_SYNCHRONY_WAITING_CONFIG_TIME} fi done atl_log "=== END: Waiting for confluence.cfg.xml available in shared home folder ===" } ###################################################################### # Start Synchrony service waitForConfluenceConfigInSharedHome exec ${_RUNJAVA} \ ${SYNCHRONY_CLASSPATH} \ ${ATL_SYNCHRONY_JVM_PROPERTIES} \ -Djwt.private.key=${SYNCHRONY_JWT_PRIVATE_KEY} \ -Djwt.public.key=${SYNCHRONY_JWT_PUBLIC_KEY} \ synchrony.core sql