0

I am having trouble getting environment variables to resolve On a Linux VM when I start up a WildFly java application.

<system-properties>
        <property name="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
        <property name="appname.url" value="https://${env.Environment}/appname"/>
</system-properties>

When I echo that environment variable (defined in /etc/environment) I get the following:

[ ~ ]$ echo $Environment
tst

I've tried updating the standalone.xml to have this these two properties set to true:

<subsystem xmlns="urn:jboss:domain:ee:4.0">
            <spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
            <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>

Also tried updating bin/jboss-cli.xml with this setting set to true:

<resolve-parameter-values>true</resolve-parameter-values>

Starting the application using it's service (i.e., systemctl restart appname) throws errors in the logs like this:

ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("system-property" => "appname.url")]) - failure description: "WFLYCTL0211: Cannot resolve expression 'https://${env.Environment}/appname'"

Unfortunately, this does not resolve my issue. Any ideas?

Stan
  • 1,191
  • 2
  • 15
  • 27
  • I use wildfly for tests but not that well. There is no coherence with /etc/environment , take a look at this, it is simple enough, the form you use required ./standalone.sh to set environment. http://www.mastertheboss.com/jbossas/jboss-configuration/how-to-use-environment-variables-in-standalone-xml-or-host-xml/?amp=1 – Samuel Marchant Oct 06 '22 at 14:46
  • @SamuelMarchant - I tried that ./standalone.sh -DEnvironment=Environment and it worked! However, I need to make sure that this works for launching from a service at the server level and not just from this shell script. Do you know how that could work? – Stan Oct 06 '22 at 16:58
  • https://stackoverflow.com/questions/18957725/set-java-opts-in-jboss-standalone-sh-file. And read the version getting sorted guide on their site. JAVA_OPTS is an environment variable used/usable in all Java startup command lines particularly servers of any make. – Samuel Marchant Oct 07 '22 at 03:45
  • 1
    "systemd" service. (ignore the posters question reason). https://stackoverflow.com/questions/42907443/wildfly-as-systemd-service – Samuel Marchant Oct 07 '22 at 04:13
  • AFAIK -D java switch enables debug in the JVM so consequently no good for running under typical use. – Samuel Marchant Oct 07 '22 at 04:15
  • This gives a good idea of what can be wrong in MS Win on a restart for a SERVICE. https://techdocs.broadcom.com/us/en/symantec-security-software/identity-security/identity-governance/14-4/installing/configure-wildfly-as-a-windows-service.html – Samuel Marchant Oct 07 '22 at 04:49
  • @SamuelMarchant you got me most of the way there! Will post the answer that worked for me. Thanks again for the help. – Stan Oct 07 '22 at 15:48
  • @ Stan Gets tangled in web server configuration, glad to have known something of how from it. – Samuel Marchant Oct 07 '22 at 16:41

1 Answers1

1

Solution for this involved a few steps to get environment variables recognized by the WildFly app's service. It isn't exactly an environment variable, it's the closest you can get. Per this thread on stackexchange, service strips all environment variables, so they cannot be referenced. Therefore, you must create a file that stores those variables and then source it in startup.

Here they are:

  1. Update bin/standalone.conf with a new line to include JAVA_OPTS="$JAVA_OPTS -Denv.Environment=$Environment"
  2. Create /etc/default/appname file so it can be sourced later on. That file only contains the line Environment=tst
  3. Update /etc/init.d/appname file with
    [ -f /etc/default/appname ] && . /etc/default/appname
    export Environment
    
  4. reload systemctl's daemon systemctl daemon-reload
  5. restart the service systemctl restart appname
Stan
  • 1,191
  • 2
  • 15
  • 27