bstopp/puppet-aem

View on GitHub
templates/start.erb

Summary

Maintainability
Test Coverage
#!/bin/bash
#
# ************************************
# Managed by Puppet AEM Module
# ************************************
#
# The original start script that came with the AEM installation 
# is named 'start-orig' in this folder.
#

if [ $FILE_SIZE_LIMIT ]; then
    CURRENT_ULIMIT=`ulimit`
    if [ $CURRENT_ULIMIT != "unlimited" ]; then
        if [ $CURRENT_ULIMIT -lt $FILE_SIZE_LIMIT ]; then
            echo "ulimit ${CURRENT_ULIMIT} is too small (must be at least ${FILE_SIZE_LIMIT})"
            exit 1
        fi
    fi
fi

BIN_PATH=$(dirname $0)
cd $BIN_PATH/..

. bin/start-env

if [ -z $JARFILE ]; then
    JARFILE=`ls app/*.jar | head -1`
fi

CURR_DIR=$(basename $(pwd))
cd ..

START_OPTS="start -c ${CURR_DIR} -i launchpad -p ${PORT}"

if [ -n "${CONTEXT_ROOT}" ]; then
    START_OPTS="${START_OPTS} -r ${CONTEXT_ROOT}"
fi

START_OPTS="${START_OPTS} -Dsling.properties=${SLING_PROPS}"

if [ $LOG_LEVEL ]; then
    START_OPTS="${START_OPTS} -l WARN"
fi

RUN_MODES="${TYPE}"

if [ -n "${RUNMODES}" ]; then
    RUN_MODES="${RUN_MODES},${RUNMODES}"
fi

if [ -n "${SAMPLE_CONTENT}" ]; then
    RUN_MODES="${RUN_MODES},${SAMPLE_CONTENT}"
fi

if [ -n "${DEBUG_PORT}" ]; then
    DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT}"
fi

JVM_OPTS="${JVM_MEM_OPTS} ${DEFAULT_JVM_OPTS} ${JVM_OPTS} ${DEBUG_OPTS} -Dsling.run.modes=${RUN_MODES}"

(
  (
    java $JVM_OPTS -jar $CURR_DIR/$JARFILE $START_OPTS &
    echo $! > $CURR_DIR/conf/cq.pid
  ) >> $CURR_DIR/logs/stdout.log 2>&1
) &

# This is here to make sure that the PID file can be created if using a Service
# Otherwise it may not exist when monitoring starts.
sleep 15