|
| 1 | +#!/usr/bin/env bash |
| 2 | +echo "Setting parameters from $CATALINA_BASE/bin/setenv.sh" |
| 3 | +echo "_____________________________________________________" |
| 4 | + |
| 5 | +# Default Ports |
| 6 | +export HTTP_PORT=8080 |
| 7 | +export HTTPS_PORT=5443 |
| 8 | +export AJP_PORT=3009 |
| 9 | +# Disable shutdown port |
| 10 | +export SHUTDOWN_PORT=-1 |
| 11 | + |
| 12 | + |
| 13 | +# The hotspot server JVM has specific code-path optimizations |
| 14 | +# Which yield an approximate 102 gain over the client version. |
| 15 | + |
| 16 | +export CATALINA_OPTS="$CATALINA_OPTS -server" |
| 17 | + |
| 18 | + |
| 19 | +# discourage address map swapping by setting Xms and Mmx to the same value |
| 20 | +# http: //confluence.atlassian. com/display/DOC/Garbage+Collector+PerformancetIssues |
| 21 | +# export CATALINA_OPTS="$CATALINA_OPTS -Xms512m -Xmx512m" |
| 22 | + |
| 23 | +# Java 10 introduced +UseContainerSupport (enabled by default) which makes the JVM use sane defaults in a container environment. |
| 24 | +# This feature is backported to Java 8 since 8u191. -XX:1UseContainerSupport allows the JVM to read cgroup limits like |
| 25 | +# available CPUs and RAM from the host machine and configure itself accordingly. Doing so allows the JVM to die with |
| 26 | +# an OutOfMemoryError instead of the container being killed. The flag is available on Java 8u191+, 10 and newer. |
| 27 | +# The old (and somewhat broken) flags -XX:{Min|Max}RAMFraction are now deprecated. |
| 28 | +# There is a new flag -MN:MaxRAMPercentage, that takes a value between 0.0 and 100.0 and defaults to 25.0. |
| 29 | + |
| 30 | +# With reasonable RAM limits (> 1 GB) we default to -XX:MaxRAMPercentage=80.0. This leaves enough free RAM for |
| 31 | +# other processes like a debug shell and doesn't waste too many resources. |
| 32 | + |
| 33 | +export JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 $JAVA_OPTS" |
| 34 | + |
| 35 | +# Increase maximum perm size for web base applications to 4x the default amount |
| 36 | +# http: //wiki.apache.org/tomcat/FAQ/Memory |
| 37 | +# Removed in Tomcat 8 |
| 38 | +# export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m" |
| 39 | + |
| 40 | +# Oracle Java as default, uses the serial garbage collector on the |
| 41 | +# Full Tenured heap. The Young space is collected in parallel, but the |
| 42 | +# Tenured is not. This means that at a time of load if a full collection |
| 43 | +# event occurs, since the event is a 'stop-the-world' serial event then |
| 44 | +# all application threads other than the garbage collector thread are |
| 45 | +# taken off the CPU. This can have severe consequences if requests continue |
| 46 | +# to accrue during these 'outage' periods. (specifically webservices, webapps} |
| 47 | +# [Also enables adaptive sizing automatically] |
| 48 | +export CATALINA_OPTS="$CATALINA_OPTS -XX: +UseParallelGc" |
| 49 | + |
| 50 | +# This is interpreted as a hint to the garbage collector that pause times |
| 51 | +# of <nnn> milliseconds or less are desired. The garbage collector will |
| 52 | +# adjust the Java heap size and other garbage collection related parameters |
| 53 | +# in an attempt to keep garbage collection pauses shorter than <nnn> milliseconds. |
| 54 | +# http://java.sun.com/docs/hotspot/gc5.0/ergo5.html |
| 55 | + |
| 56 | +export CATALINA_OPTS="$CATALINA_OPTS -XX: MaxGCPauseMillis=1500" |
| 57 | + |
| 58 | +# Verbose GC |
| 59 | +export CATALINA_OPTS="$CATALINA_OPTS -verbose:gc" |
| 60 | +#export CATALINA_OPTS="$CATALINA_OPTS -Xloggc:$CATALINA_BASE/logs/gc.log" |
| 61 | +export CATALINA_OPTS="$CATALINA_OPTS -XX:+PrintGcDetails" |
| 62 | +#export CATALINA_OPTS="$CATALINA_OPTS -XX:+PrintGCDateStamps" |
| 63 | +#export CATALINA_OPTS="$CATALINA_OPTS -XX:+PrintGCApplicationStoppedTime" |
| 64 | + |
| 65 | +# Disable remote (distributed) garbage collection by Java clients |
| 66 | +# and remove ability for applications to call explicit GC collection |
| 67 | +export CATALINA_OPTS="$CATALINA_OPTS -XX:+DisableExplicitGC" |
| 68 | + |
| 69 | +# Prefer IPv4 over IPv6 stack |
| 70 | +export CATALINA_OPTS="$CATALINA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Address=true" |
| 71 | + |
| 72 | +# Set Java Server TimeZone to UIC |
| 73 | +export CATALINA_OPTS="$CATALINA_OPTS -Duser.timezone=${USER_TIMEZONE:-UTC}" |
| 74 | + |
| 75 | +# IP ADDRESS OF CURRENT MACHINE |
| 76 | +if hash ip 2>&- |
| 77 | +then |
| 78 | + IP=`ip addr show | grep 'global eth[0-9]' | grep -o 'inet [0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+' | grep -o '[0-9]\+.[0-9] \+.[0-9] \+.[0-9]\+'` |
| 79 | +else |
| 80 | + IP=`ifconfig | grep 'inet [0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+.*broadcast' | grep -o 'inet [0-9]\+.[0-9]\+. [0-9] \+.[0-9]\+' | grep -o '[0-9]\+.[0-9]\+.[0-9\+.[0-9]\+'` |
| 81 | +fi |
| 82 | + |
| 83 | +# Check for application specific parameters at startup |
| 84 | +if [ -r "$CATALINA_BASE/bin/appenv.sh" ]; then |
| 85 | + . "$CATALINA_BASE/bin/appenv.sh" |
| 86 | +fi |
| 87 | + |
| 88 | +# Specifying JMX settings |
| 89 | +if [ -z $JME_PORT ]; then |
| 90 | + echo "JMX Port not specified. JMX interface disabled.\n" |
| 91 | +else |
| 92 | + echo "JMM interface is enabled on port $JMX_PORT\n" |
| 93 | + # Consider adding -Djava.rmi.server.hostname=<host ip> |
| 94 | + export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote \ |
| 95 | + -Dcom.sun.management .jmxremote.port=$JMX_PORT \ |
| 96 | + -Dcom.sun.management.jmxremote.ssl=false \ |
| 97 | + -Dcom. sun. management. jmxremote.authenticate-false \ |
| 98 | + -Djava.rmi.server.hostname=$IP" |
| 99 | +fi |
| 100 | + |
| 101 | +# Export ports |
| 102 | +export CATALINA_OPTS="$CATALINA_OPTS -Dport.http=$HTTP_PORT" |
| 103 | +export CATALINA_OPTS="$CATALINA_OPTS -Dport.shutdown=$SHUTDOWN PORT" |
| 104 | +export CATALINA_OPTS="$CATALINA_OPTS -Dport.https=$HTTPS PORT" |
| 105 | +export CATALINA_OPTS="$CATALINA_OPTS -Dport.ajp=$AJP_PORT" |
| 106 | + |
| 107 | +# export JAVA_ENDORSED_DIRS="$CATALINA_BASE/endorsed:$CATALINA_HOME/endorsed" |
| 108 | + |
| 109 | +# Add log location although in container we are not suppose to write logs to file |
| 110 | +export CATALINA_OPTS="$CATALINA_OPTS -Dlog.location=${CATALINA_HOME} /logs/" |
| 111 | + |
| 112 | +# Add $CATALINA_HOME/config/ and any existing $CLASSPATH into Tomcat classpath |
| 113 | +export CLASSPATH="$CATALINA_HOME/config/:$CLASSPATH" |
| 114 | + |
| 115 | +# Set Spring config dir to config folder to let spring look for spring configuration files here |
| 116 | +# https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files |
| 117 | +export JAVA_OPTS="$JAVA_OPTS -Dspring.config.location=$ {CATALINA_HOME}/config/" |
| 118 | + |
| 119 | +# Add ROOT Certificate and Intermediate certificates to trustStore and trust them in mal |
| 120 | +# export JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.trustStore=/tmp/TrustStore.jks -Djavax.net.ssl.trustStorePassword=abcd1234" |
| 121 | + |
| 122 | +echo "Using CATALINA_OPTS:" |
| 123 | +for arg in $CATALINA_OPTS |
| 124 | +do |
| 125 | + echo ">> " $arg |
| 126 | +done |
| 127 | +echo "" |
| 128 | + |
| 129 | +# echo "Using JAVA_OPTS:" |
| 130 | +# for arg in $JAVA_OPTS |
| 131 | +# do |
| 132 | +# echo ">> " $arg |
| 133 | +# done |
| 134 | + |
| 135 | +echo "___________________________________" |
| 136 | +echo "" |
| 137 | + |
0 commit comments