diff --git a/README.md b/README.md index 82cd484..ad41d4a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ DATABASE_NAME [ jamfsoftware ] DATABASE_USERNAME [ jamfsoftware ] DATABASE_PASSWORD [ jamfsw03 ] DATABASE_PORT [ 3306 ] +JDBC_PARAMETERS [ ] JMXREMOTE true / [ false ] JMXREMOTE_PORT @@ -77,6 +78,9 @@ tomcat_host_stuck_threads_threshold - 600 This image requires that either a `/data/ROOT.war` be bind-mounted and exist, or the `/usr/bin/tomcat/webapps/ROOT` directory exist. A ROOT.war will be auto-unpacked and configured based upon the above environment variables, or if the ROOT directory already exists, nothing will be unpacked but logging paths, database information, JMX, and Java opts will be set. +## File Override Config +The `DataBase.xml` file can be optionally mounted into the container's `/config` directory, this will override any environment variables set. + ## Example Run a basic JamfPro instance with port 8080 exposed locally on port 8080, setup remote database, bind-mounted ROOT.war, and bind-mounted webapps directory. diff --git a/configuration.sh b/configuration.sh index bf44412..1fdc9e1 100755 --- a/configuration.sh +++ b/configuration.sh @@ -1,5 +1,7 @@ #!/bin/bash -e +WEBAPPS_DIR="/usr/local/tomcat/webapps" + ########################################################## ####################### Functions ######################## echo_time() { @@ -13,17 +15,17 @@ unpack_root_war() { exit 1 fi #Unpack the warfile - echo_time "Unpacking ROOT.war to /usr/local/tomcat/webapps/ROOT \n" - unzip -q /data/ROOT.war -d /usr/local/tomcat/webapps/ROOT + echo_time "Unpacking ROOT.war to ${WEBAPPS_DIR}/ROOT \n" + unzip -q /data/ROOT.war -d ${WEBAPPS_DIR}/ROOT } setup_linux_logging_paths() { #Replace Mac logging paths with linux based paths echo_time "Set logging file paths to use linux file paths" CONFIG_FILES=( - "/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties" - "/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml" - "/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/ESAPI.properties" + "${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j.properties" + "${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j2.xml" + "${WEBAPPS_DIR}/ROOT/WEB-INF/classes/ESAPI.properties" ) for config in "${CONFIG_FILES[@]}"; do if test -f "${config}"; then @@ -38,54 +40,63 @@ setup_stdout_logging() { #Add stdout output for Jamf specific log files while maintaining logging to the files echo_time "STDOUT_LOGGING is true, add stdout logging for all logfiles" #Check whether log4j.properties (<= Jamf Pro 10.30.3) or log4j2.xml (>= Jamf Pro 10.31.0) exists - FILE=/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + FILE=${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j.properties if test -f "$FILE"; then echo_time "Found log4j.properties, enable logging to stdout" - if grep -Fxq "log4j.rootLogger=INFO,JAMF,stdout" /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties; then + if grep -Fxq "log4j.rootLogger=INFO,JAMF,stdout" ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j.properties; then echo_time "stdout logging appears to be present in log4j.properties file, skipping" else echo_time "Add stdout logging to log4j.properties file" sed -e '/log4j.rootLogger/ {r /log4j.stdout.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + d}' -i ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j.properties fi else echo_time "Found log4j2.xml, enable logging to stdout" - if grep -Fxq ' ' /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml; then + if grep -Fxq ' ' ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j2.xml; then echo_time "stdout logging appears to be present in log4j2.xml file, skipping" else echo_time "Add stdout logging to log4j2.xml file" sed -e '// {r /log4j2.stdout.appenders.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + d}' -i ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j2.xml sed -e '// {r /log4j2.stdout.loggers.root.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + d}' -i ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j2.xml sed -e '// {r /log4j2.stdout.loggers.analytics.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + d}' -i ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j2.xml sed -e '// {r /log4j2.stdout.loggers.vpp.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + d}' -i ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/log4j2.xml fi fi fi } setup_remote_database() { - DATABASE_HOST=${DATABASE_HOST:-localhost} - DATABASE_NAME=${DATABASE_NAME:-jamfsoftware} - DATABASE_USERNAME=${DATABASE_USERNAME:-jamfsoftware} - DATABASE_PASSWORD=${DATABASE_PASSWORD:-jamfsw03} - DATABASE_PORT=${DATABASE_PORT:-3306} - - echo_time "\n\nDatabase connection information: \n DATABASE_HOST: ${DATABASE_HOST} \n DATABASE_NAME: ${DATABASE_NAME} \n DATABASE_USERNAME: ${DATABASE_USERNAME}\n\n" - - echo_time "Setting up the DataBase.xml file to use remote MySQL database" - if [ ! -f "/usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml" ]; then - echo_time "FATAL ERROR: DataBase.xml not where expected, cannot continue" - exit 1 + if [[ -f "/config/DataBase.xml" ]]; then + echo_time "Database xml config override found, ignoring environment variables" + cp /config/DataBase.xml ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml else - sed -i s#\$DATABASE_HOST\# /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml - sed -i s#\$DATABASE_NAME\# /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml - sed -i s#\$DATABASE_USERNAME\# /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml - sed -i s#\$DATABASE_PASSWORD\# /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml - sed -i s#\$DATABASE_PORT\# /usr/local/tomcat/webapps/ROOT/WEB-INF/xml/DataBase.xml + DATABASE_HOST=${DATABASE_HOST:-localhost} + DATABASE_NAME=${DATABASE_NAME:-jamfsoftware} + DATABASE_USERNAME=${DATABASE_USERNAME:-jamfsoftware} + DATABASE_PASSWORD=${DATABASE_PASSWORD:-jamfsw03} + DATABASE_PORT=${DATABASE_PORT:-3306} + + echo_time "\n\nDatabase connection information: \n DATABASE_HOST: ${DATABASE_HOST} \n DATABASE_NAME: ${DATABASE_NAME} \n DATABASE_USERNAME: ${DATABASE_USERNAME}\n\n" + + echo_time "Setting up the DataBase.xml file to use remote MySQL database" + if [ ! -f "${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml" ]; then + echo_time "FATAL ERROR: DataBase.xml not where expected, cannot continue" + exit 1 + else + sed -i s#\$DATABASE_HOST\# ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml + sed -i s#\$DATABASE_NAME\# ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml + sed -i s#\$DATABASE_USERNAME\# ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml + sed -i s#\$DATABASE_PASSWORD\# ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml + sed -i s#\$DATABASE_PORT\# ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml + if [[ -n "${JDBC_PARAMETERS}" ]]; then + echo_time "JDBC environment variable is set, replacing JDBC database config" + sed -i s#\${JDBC_PARAMETERS}\# ${WEBAPPS_DIR}/ROOT/WEB-INF/xml/DataBase.xml + fi + fi fi } @@ -127,14 +138,14 @@ setup_java_opts() { create_cache_properties(){ echo_time "Setting up the cache.properties to be memcached" - cat <<-EOF > /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/dal/cache.properties + cat <<-EOF > ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/dal/cache.properties cache.type=memcached EOF } create_memcached_properties(){ echo_time "Setting up the memcached.properties" - cat <<-EOF > /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/dal/memcached.properties + cat <<-EOF > ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/dal/memcached.properties memcached.endpoints[0]=$MEMCACHED_HOST memcached.timeToLiveSeconds=120 EOF @@ -152,7 +163,7 @@ tomcatServerXML() { ########################################################## create_cluster_properties() { echo_time "Creating the clustering properties file" -cat <<- EOF > /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/clustering.properties +cat <<- EOF > ${WEBAPPS_DIR}/ROOT/WEB-INF/classes/clustering.properties cluster.settings.enabled=true cluster.settings.monitor_frequency=60 cluster.node[0]=$1 @@ -164,12 +175,12 @@ EOF ####################### Executions ####################### echo_time "Check if Tomcat ROOT directory exists, will NOT overwrite if exists" -if [ ! -d /usr/local/tomcat/webapps/ROOT ]; then - echo_time "/usr/local/tomcat/webapps/ROOT directory does not exist, attempt to deploy ROOT.war from /data" +if [ ! -d ${WEBAPPS_DIR}/ROOT ]; then + echo_time "${WEBAPPS_DIR}/ROOT directory does not exist, attempt to deploy ROOT.war from /data" unpack_root_war else - echo_time "/usr/local/tomcat/webapps/ROOT exists, skipping ROOT.war deploy" + echo_time "${WEBAPPS_DIR}/ROOT exists, skipping ROOT.war deploy" fi # Check to see if clustering should be enabled by existence of PRIMARY_NODE_NAME