This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| #!/bin/bash | |
| function print_sed_exp_replace_env_var { | |
| sed_exp="" | |
| for openshift_var in $(env | grep ^OPENSHIFT_ | awk -F '=' '{print $1}') | |
| do | |
| # environment variable values that contain " or / need to be escaped | |
| # or they will cause problems in the sed command line. | |
| variable_val=$(echo "${!openshift_var}" | sed -e "s@\/@\\\\/@g" | sed -e "s/\"/\\\\\"/g" | sed "s/'/\\\'/g") | |
| # the entire sed s/search/replace/g command needs to be quoted in case the variable value | |
| # contains a space. | |
| sed_exp="${sed_exp} -e \"s/\\\${env.${openshift_var}}/${variable_val}/g\"" | |
| done | |
| printf "%s\n" "$sed_exp" | |
| } | |
| CART_DIR=${OPENSHIFT_JBOSSEAP_DIR} | |
| # if the repo contains a standalone.xml, back it up | |
| if [ -f ${OPENSHIFT_REPO_DIR}.openshift/config/standalone.xml ] | |
| then | |
| cp ${OPENSHIFT_REPO_DIR}.openshift/config/standalone.xml $OPENSHIFT_JBOSSEAP_DIR/jboss_cfg_backup/standalone.xml || : | |
| fi | |
| # Create a link for each file in user config to server standalone/config | |
| if [ -d ${OPENSHIFT_REPO_DIR}.openshift/config ] | |
| then | |
| for f in ${OPENSHIFT_REPO_DIR}.openshift/config/* | |
| do | |
| target=$(basename $f) | |
| if [ $target = "standalone.xml" ] | |
| then | |
| # don't replace standalone.xml from the repository, we'll make a decision | |
| # about whether to do that or not later. | |
| continue | |
| fi | |
| # Remove any target that is being overwritten | |
| if [ -e "${CART_DIR}/standalone/configuration/$target" ] | |
| then | |
| echo "Removing existing $target" | |
| rm -rf "${CART_DIR}/standalone/configuration/$target" | |
| cp ${OPENSHIFT_REPO_DIR}.openshift/config/$target ${CART_DIR}/standalone/configuration | |
| fi | |
| done | |
| fi | |
| # Whether or not we found a standalone.xml in the repo, copy the last version of the standalone.xml | |
| # that came from the repo, to be the config, unless the user is in jbosscli mode in which case | |
| # we don't touch standalone.xml. | |
| if [ -f $OPENSHIFT_JBOSSEAP_DIR/jboss_cfg_backup/standalone.xml ] && [ x$DISABLE_OPENSHIFT_MANAGED_SERVER_CONFIG != "xtrue" ] | |
| then | |
| cp $OPENSHIFT_JBOSSEAP_DIR/jboss_cfg_backup/standalone.xml ${OPENSHIFT_JBOSSEAP_DIR}/standalone/configuration/standalone.xml || : | |
| fi | |
| MYSQL_ENABLED="false" | |
| if [ -n "$OPENSHIFT_MYSQL_DB_URL" ] | |
| then | |
| MYSQL_ENABLED="true" | |
| fi | |
| POSTGRESQL_ENABLED="false" | |
| if [ -n "$OPENSHIFT_POSTGRESQL_DB_URL" ] | |
| then | |
| POSTGRESQL_ENABLED="true" | |
| fi | |
| max_threads=$(ulimit -u) | |
| if ! [[ "$max_threads" =~ ^[0-9]+$ ]] ; then | |
| max_threads=1024 | |
| fi | |
| if [ -z "$JVM_HEAP_RATIO" ]; then | |
| JVM_HEAP_RATIO=0.5 | |
| fi | |
| if [ -z "$JVM_PERMGEN_RATIO" ]; then | |
| JVM_PERMGEN_RATIO=0.2 | |
| fi | |
| if [ -z "$MESSAGING_THREAD_RATIO" ]; then | |
| MESSAGING_THREAD_RATIO=0.2 | |
| fi | |
| max_memory_mb=${OPENSHIFT_GEAR_MEMORY_MB} | |
| max_heap=$( echo "$max_memory_mb * $JVM_HEAP_RATIO" | bc | awk '{print int($1+0.5)}') | |
| max_permgen=$( echo "$max_memory_mb * $JVM_PERMGEN_RATIO" | bc | awk '{print int($1+0.5)}') | |
| messaging_thread_pool_max_size=$( echo "$max_threads * $MESSAGING_THREAD_RATIO" | bc | awk '{print int($1+0.5)}') | |
| messaging_scheduled_thread_pool_max_size=5 | |
| # $( echo "$max_threads * $MESSAGING_THREAD_RATIO" | bc | awk '{print int($1+0.5)}') | |
| if [ $max_permgen -gt 256 ] | |
| then | |
| max_permgen=256 | |
| fi | |
| memory_options="-Xms40m -Xmx${max_heap}m -XX:MaxPermSize=${max_permgen}m -XX:+AggressiveOpts -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90" | |
| if [ $max_heap -lt 1024 ] | |
| then | |
| memory_options="${memory_options} -Dorg.apache.tomcat.util.LOW_MEMORY=true" | |
| fi | |
| if [ -z "${OPENSHIFT_JBOSSEAP_CLUSTER_PROXY_PORT}" ]; then | |
| export OPENSHIFT_JBOSSEAP_CLUSTER_PROXY_PORT=7600 | |
| fi | |
| if [ -z "${OPENSHIFT_JBOSSEAP_CLUSTER}" ]; then | |
| export OPENSHIFT_JBOSSEAP_CLUSTER="${OPENSHIFT_JBOSSEAP_IP}[${OPENSHIFT_JBOSSEAP_CLUSTER_PORT}]" | |
| fi | |
| sed_replace_env=$(print_sed_exp_replace_env_var) | |
| # Timestamp based filename for uniquenss. | |
| # %s%N would be more unique but is not portable outside of linux | |
| systime=`date +%s` | |
| # Due to how bash handles quotes within variables, we need to write the entire | |
| # sed command out to a file and then run it, rather than running the sed | |
| # command directly from within the script, passing the variables as arguments | |
| # See http://mywiki.wooledge.org/BashFAQ/050 | |
| cat <<EOF > /tmp/sed_${systime}.sh | |
| sed -i -e "s/\\\${mysql.enabled}/$MYSQL_ENABLED/g" \ | |
| -e "s/\\\${postgresql.enabled}/$POSTGRESQL_ENABLED/g" \ | |
| -e "s/\\\${messaging.thread.pool.max.size}/$messaging_thread_pool_max_size/g" \ | |
| -e "s/\\\${messaging.scheduled.thread.pool.max.size}/$messaging_scheduled_thread_pool_max_size/g" \ | |
| -e "s/\\\${env.OPENSHIFT_INTERNAL_IP}/${OPENSHIFT_JBOSSEAP_IP}/g" \ | |
| ${sed_replace_env} \ | |
| ${CART_DIR}/standalone/configuration/standalone.xml > /dev/null 2>&1 | |
| EOF | |
| . /tmp/sed_${systime}.sh | |
| rm /tmp/sed_${systime}.sh | |
| # | |
| # Specify options to pass to the Java VM. | |
| # | |
| if [ -z "$JAVA_OPTS" ]; then | |
| JAVA_OPTS="$memory_options -DOPENSHIFT_APP_UUID=${OPENSHIFT_APP_UUID} -Dorg.jboss.resolver.warning=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -Djboss.node.name=${OPENSHIFT_GEAR_DNS} -Djgroups.bind_addr=${OPENSHIFT_JBOSSEAP_IP} -Dorg.apache.coyote.http11.Http11Protocol.COMPRESSION=on" | |
| if [ ! -z "$ENABLE_JPDA" ]; then | |
| JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=${OPENSHIFT_JBOSSEAP_IP}:8787,server=y,suspend=n ${JAVA_OPTS}" | |
| fi | |
| fi | |
| if [ -n "$JAVA_OPTS_EXT" ]; then | |
| JAVA_OPTS="$JAVA_OPTS $JAVA_OPTS_EXT" | |
| fi | |
| export JBOSS_MODULEPATH=${OPENSHIFT_REPO_DIR}/.openshift/config/modules | |
| if [ ! -z $OPENSHIFT_JBOSSEAP_MODULE_PATH ]; then | |
| export JBOSS_MODULEPATH=$JBOSS_MODULEPATH:$OPENSHIFT_JBOSSEAP_MODULE_PATH | |
| fi | |
| export JBOSS_MODULEPATH=$JBOSS_MODULEPATH:${CART_DIR}/modules | |
| export JAVA_OPTS | |