Pivotal Knowledge Base

Follow

How to store database configuration at a shared location

Environment

Product Version
Pivotal tc Server  

 Purpose

This article outlines the steps involved in storing the database configuration at a shared location such as /etc/app/database.properties, if you have multiple tc Server instances and the database configuration is shared among them. This will help us in avoiding multiple updates for any reason; for example, if the database password were to change very frequently.

 Procedure 

The following steps are needed to make this change:

  1. Create a properties file, say db.properties in /etc/app-cfg/db.properties. This path could be any shared location accessible to the tcServer instances.
    username = root
    password = test
    
  2. In the server.xml file inside the server configuration, add the following:
    <Listener className="com.springsource.tcserver.properties.SystemProperties" 
    file.1="/etc/app-cfg/db.properties" 
    immutable="false" 
    trigger="now" />
    This will read in the system properties from the file we created in step #1 and make the properties accessible in the Apache Tomcat configuration. You may refer here for more details on adding a System Properties Listener.
  3. In the context.xml file, inside your app's WebContent/META-INF, add the following:
    <Resource name="jdbc/swagata" 
    auth="Container" 
    type="javax.sql.DataSource" 
    maxActive="100" 
    maxIdle="30" 
    maxWait="-1" 
    validationQuery="SELECT 1" 
    testOnBorrow="true" 
    username="${username}" 
    password="${password}" 
    driverClassName="com.mysql.jdbc.Driver" 
    url="jdbc:mysql://localhost:3306/java_one_2014"/>
    Here, ${username} and ${password} refer to the system properties defined in the db.properties file, which was created in step #1.
  4. Build and deploy the War file.
  5. Restart the server.

Comments

Powered by Zendesk