What is environment variable in opensh

2019-07-31 01:37发布

问题:

How can I to set enabled = "true" on datasource of standalone.xml of Openshift v3 Wildfly container like below.

<datasource jndi-name="java:jboss/datasources/MySQLDS" enabled="true" use-java-context="true" pool-name="MySQLDS" use-ccm="true">

I put the OPENSHIFT_MYSQL_ENABLED environment variable to "true" but nothing happended.


The answer reference site is the below URL:

https://developer.jboss.org/wiki/DataserviceBuilderOnOpenShiftV3Online

回答1:

I was dealing with the same problem: the environment variable OPENSHIFT_MYSQL_ENABLED is being ignored by variable substitution process, so I had to activate the data source with my bare hands, and that's what I did: (I'm going to assume you have the OC tools installed on your system)

  1. log into OC: oc login
  2. list all pods and find the WildFly instance: oc get pods
  3. enter the container's SSH console: oc rsh <<pod-name>>
  4. edit the standalone.xml file vi /wildfly/standalone/configuration/standalone.xml
  5. search for the word "datasource" by typing /datasource on vi editor then press enter
  6. find the attribute "enabled" of your data source and update its value from false to true (to do so, press i to go to vi insert mode)
  7. save the file by pressing esc then :x

I'm using OpenShift community edition, so to restart the container is always a hassle: it takes a very long time to find resources available (like memory and CPU) and start the server again, however, you won't have your data source enabled unless you restart the server. In this regard, to do so, you don't need to restart the container, just reload WildFly by using jboss-cli.sh command line tools. (I didn't try to kill the process and start it again, so if you did try, please comment if it worked). The following steps should be executed on container's terminal using oc rsh <<podname>> or using the terminal on web console.

  1. Enter jboss-cli using the command /wildfly/bin/jboss-cli.sh
  2. Type connect to log into the WildFly console, you'll be prompted for user and password. If you do not have credentials, exit this console and create a management user by executing the script /wildfly/bin/add-user.sh
  3. Check your data source properties by typing data-source read-resource --name=<<YOUR_DATASOURCE_NAME>> --include-runtime=true --recursive=true and follow up on the "enabled" property.
  4. If your data source is disabled, you should enable it by entering the command data-source enable --name=<<YOUR_DATASOURCE_NAME>>
  5. reload WildFly by entering the reload command. Once WildFly reboots you'll need to access jboss-cli.sh and log into the console again.
  6. test your data source connection using the command data-source test-connection-in-pool --name=<<YOUR_DATASOURCE_NAME>>. If the command output was true your data source is up and running.

Openshift v3 is based on docker containers, therefore I'm afraid if you do restart the container, this configuration will probably be lost. The most appropriated solution would be to include this actions on docker's script, which I don't know yet how it works along with Openshift platform.

Hope it helps!