Appendix E. Customizing JVM environment variables
You can use JVM environment variables to set all the options for the Fuse on OpenShift images.
E.1. Using S2I Java builder image with OpenJDK 8
Using the S2I Java builder image you can run results directly without using any other application server. This S2I image is suitable for microservices with a flat classpath (including fat jars
).
You can configure Java options when using the Fuse on OpenShift images. For the JVM options, you can use the environment variable JAVA_OPTIONS
. Also, provide JAVA_ARGS
for the arguments which are given through to the application.
E.2. Using S2I Karaf builder image with OpenJDK 8
The S2I Karaf builder image can be used with OpenShift’s Source To Image workflow to build Karaf4 custom assembly based maven projects.
Procedure
- Use following command to use S2I workflow.
s2i build <git repo url> registry.redhat.io/fuse7/fuse-karaf-openshift:1.13 <target image name> docker run <target image name>
E.2.1. Configuring the Karaf4 assembly
The location of the Karaf4 assembly built by the maven project can be provided in multiple ways.
-
Default assembly file
*.tar.gz
in output directory -
By using the
-e flag
in sti or oc command -
By setting
FUSE_ASSEMBLY
property in.sti/environment
under the project source
E.2.2. Customizing the Maven build
It is possible to customize the maven build. The MAVEN_ARGS
environment variable can be set to change the behaviour. By default, the MAVEN_ARGS
is set as follows:
`Karaf4: install karaf:assembly karaf:archive -DskipTests -e`
E.3. Build time environment variables
Following are the environment variables that are used to influence the behaviour of S2I Java and Karaf builder images during the build time.
-
MAVEN_ARGS
: Arguments to use when calling maven, replacing the default package. -
MAVEN_ARGS_APPEND
: Additional Maven arguments, useful for adding temporary arguments like-X
or-am
-pl
. -
ARTIFACT_DIR
: Path totarget/
where the jar files are created for multi-module builds. These are added to${MAVEN_ARGS}
. -
ARTIFACT_COPY_ARGS
: Arguments to use when copying artifacts from the output directory to the application directory. Useful to specify which artifacts will be part of the image. -
MAVEN_CLEAR_REPO
: If set, removes the Maven repository after you build the artifact. This is useful for keeping the application image small, however, It prevents the incremental builds. The default value is false.
E.4. Run time environment variables
You can use the following environment variables to influence the run script.
-
JAVA_APP_DIR
: the directory where the application resides. All paths in your application are relative to the directory. -
JAVA_LIB_DIR
: this directory contains the Java jar files as well an optional classpath file, which holds the classpath. Either as a single line classpath (colon separated) or with jar files listed line-by-line. However, If not set, thenJAVA_LIB_DIR
is the same asJAVA_APP_DIR
directory. -
JAVA_OPTIONS
: options to add when calling java. -
JAVA_MAX_MEM_RATIO
: It is used when no-Xmx
option is given in JAVA_OPTIONS. This is used to calculate a default maximal heap Memory based on a containers restriction. If used in a Docker container without any memory constraints for the container, then this option has no effect. -
JAVA_MAX_CORE
: It manually restricts the number of cores available, which is used for calculating certain defaults like the number of garbage collector threads. If set to 0, you cannot perform the base JVM tuning based on the number of cores. -
JAVA_DIAGNOSTICS
: Set this to fetch some diagnostics information, to standard out when things are happening. -
JAVA_MAIN_CLASS
: A main class to use as an argument for java. When you use this environment variable, all jar files in$JAVA_APP_DIR
directory are added to the classpath and in the$JAVA_LIB_DIR
directory. -
JAVA_APP_JAR
: A jar file with an appropriate manifest, so that you can start withjava -jar
. However, if it is not provided, then$JAVA_MAIN_CLASS
is set. In all cases, this jar file is added to the classpath. -
JAVA_APP_NAME
: Name to use for the process. -
JAVA_CLASSPATH
: the classpath to use. If not given, the startup script checks for a file${JAVA_APP_DIR}/classpath
and use its content as classpath. If this file doesn’t exists, then all jars in the application directory are added under(classes:${JAVA_APP_DIR}/*)
. -
JAVA_DEBUG
: If set, remote debugging will be switched on. -
JAVA_DEBUG_PORT
: Port used for remote debugging. The default value is 5005.
E.5. Jolokia configuration
You can use the following environment variables in Jolokia:
-
AB_JOLOKIA_OFF
: If set, disables the activation of Jolokia (echos an empty value). By default, Jolokia is enabled. -
AB_JOLOKIA_CONFIG
: If set, uses the file (including path) as Jolokia JVM agent properties. However, If not set, the/opt/jolokia/etc/jolokia.properties
will be created using the settings. -
AB_JOLOKIA_HOST
: Host address to bind (Default value is 0.0.0.0) -
AB_JOLOKIA_PORT
: Port to use (Default value is 8778) -
AB_JOLOKIA_USER
: User for basic authentication. By default, it isjolokia
. -
AB_JOLOKIA_PASSWORD
: Password for basic authentication. By default, authentication is switched off. -
AB_JOLOKIA_PASSWORD_RANDOM
: Generates a value and is written in/opt/jolokia/etc/jolokia.pw
file. -
AB_JOLOKIA_HTTPS
: Switch on secure communication withHTTPS
. By default, self-signed server certificates are generated, if no serverCert configuration is given inAB_JOLOKIA_OPTS
. -
AB_JOLOKIA_ID
: Agent ID to use -
AB_JOLOKIA_DISCOVERY_ENABLED
: Enables the Jolokia discovery. The default value is false. -
AB_JOLOKIA_OPTS
: Additional options to be appended to the agent configuration. Options are given in the formatkey=value
.
Here is an option for integration with various environments:
-
AB_JOLOKIA_AUTH_OPENSHIFT
: Switch on client authentication for OpenShift TSL communication. Ensure that the value of this parameter must be present in a client certificate. If you enable this parameter, it will automatically switch Jolokia intoHTTPS
communication mode. The default CA cert is set to/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
.
Application arguments can be provided by setting the variable JAVA_ARGS
to the corresponding value.