Search code examples
openshiftopenshift-origins2i

Add JAVA_OPTS to jboss-eap70-openshift


We use jboss-eap70-openshift with s2i and openshift origin 3.4. How can I add JAVA_OPTS? I do not want to overwrite them

This solution is deprecated Not able to set options in JAVA_OPTS in JBoss openshift


Solution

  • This image doesn't seem to specify the JAVA_OPTS, so you should be able to just edit the deployment config and add the environment variable there. It will be then respected by standard standalone.sh script of JBoss.

    Commands to add the environment variable to a dc:

    # list your deployment config
    oc get dc 
    
    # Set environment variable on your dc
    oc set env dc/<jboss-dc> JAVA_OPTS=<your env variables>
    

    Update after comment

    First option

    After looking into the JBoss start files, there is no easy way to do this. You can download the start scripts using:

    mkdir scripts
    cd scripts
    oc rsync <pod>:/opt/eap/bin .
    

    There you can find your message in standalone.conf file. The snippet is very simple, so you could just repeat the same settings in your environment variable.

    if [ "x$JAVA_OPTS" = "x" ]; then
       JAVA_OPTS="-Xms1303m -Xmx1303m  -Djava.net.preferIPv4Stack=true"
       JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
       JAVA_OPTS="$JAVA_OPTS -Djboss.modules.policy-permissions=true"
    else
       echo "JAVA_OPTS already set in environment; overriding default settings with values: $JAVA_OPTS"
    fi
    

    Second option

    Another solution comes to my mind. If you check standalone.sh file, you can see the following lines:

    # Read an optional running configuration file
    if [ "x$RUN_CONF" = "x" ]; then
        RUN_CONF="$DIRNAME/standalone.conf"
    fi
    if [ -r "$RUN_CONF" ]; then
        . "$RUN_CONF"
    fi
    

    It means you can pass your own initialization script in which you first execute the standalone.conf and then read some environment variable and add it to JAVA_OPTS.

    To achieve it, you need to set env variable RUN_CONF=/path/to/my/script and mount this script - easy to achieve using config maps https://docs.openshift.org/latest/dev_guide/configmaps.html#configmaps-use-case-consuming-in-volumes

    Third option

    Also in standalone.sh the SERVER_OPTS variable is created from arguments passed to standalone.sh. This variable is then later passed to starting java, so I believe you could hide your options there.

    OpenShift launches /bin/sh -c /usr/local/s2i/run on start and this script starts

    exec $JBOSS_HOME/bin/openshift-launch.sh
    

    Unfortunately in this case the openshift-launch.sh would have to be replaced, since it doesn't take more parameters when it starts JBoss:

    exec $JBOSS_HOME/bin/standalone.sh -c standalone-openshift.xml -bmanagement 127.0.0.1 $JBOSS_HA_ARGS ${JBOSS_MESSAGING_ARGS}
    

    Summary

    This image does not provide an option to extend the JAVA_OPTS. There are some ways around it, but the simplest way would be to duplicate the options that are already there when you pass them to OpenShift. At least until it is possible to extend it and not only override.