Improve the way dotCMS reads the configuration file
For some scenarios were hard coded configuration is not a viable solution, the current approach of loading dotCMS's properties is not enough.
Expected Behavior
The properties loader should be able to accept environment variables as values. For example, assuming an environment variable `REMOTE_ASSET_PATH="/mnt/remote/nfs1/cluster1/assets" inside the *dotmarketing-config.properties*: `bash ... ASSET_REAL_PATH={env.REMOTE_ASSET_PATH} ... `Whe loading the properties will transform to:`bash ... ASSET_REAL_PATH=/mnt/remote/nfs1/cluster1/assets ... ``
Current Behavior
There's no way to read from environment variables at this point
Context
An automated server deploy environment were some system properties such as remote filesystem mount paths are specified via environment variables
Your Environment
- dotCMS version used: latest
- Operating System and version: Linux
Related information
https://my.dotcms.com/tickets/detail.dot?id=28470ecd-35ec-435d-a17f-f86bd49b394b
Also need to be able to support things like:
...
ASSET_REAL_PATH=/mnt/remote/{env.SERVER}/cluster1/assets
...
and have it expand to:
...
ASSET_REAL_PATH=/mnt/remote/server1/cluster1/assets
...
Here is my thought:
- Make the config store in a Map (ConcurrentHashMap) on startup:
- read in the properties from dotmarketing and dotcms config files into the config Map
- then read all environmental variables that are prefixed with DOTCMS_ and have them set/override the config Map
- then read in all the startup -D properties that were set and are prefixed with dotcms. and have them set/override the config Map
@bgriffin69, on the variable expansion, I think it is ok to have the customer set an environmental variable called:
DOTCMS_ASSET_REAL_PATH=/mnt/remote/server1/cluster1/assets
rather than just
DOTCMS_SERVER_ID=server1
You could even do that in the shell script where you set the environmental variables, e.g.
#!/bin/sh
DOTCMS_SERVER_ID=server1
DOTCMS_ASSET_REAL_PATH=/mnt/remote/$DOTCMS_SERVER_ID/cluster1/assets
Longer term vision (for another day) Allow an admin to edit these variables at runtime. Setting these in a map begins to get us there.
that approach is mostly fine - customer requirement is that properties be configurable from environment variables - specifically, the exact same properties files and startup scripts have to be deployed on all machines in the cluster but each machine needs to be able to specify different locations
We have to be able to pull in environment variables somehow - if not in the processing of the property files, then perhaps the startup script iterates through all environment variables that start with DOTCMS_ and adds -D variables to the JVM command line
Environment variables should be available in Java via calls to System.getEnv() - https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv-java.lang.String-
PR: https://github.com/dotCMS/core/pull/11134
@john-thomas-dotcms As part of the issue we have not only implement the interpolation to handle sys and env variables in the config, but also we have introduce a functionality to dynamically reload the config when cluster or config properties has change in the filesystem; previously the configuration was check every 5 mins, so a change in the configuration would be reflected after 5 mins. So as part of this enhancement, it could be worthy to mention that as a workaround if an user changes wants to reflect a new system or env change, a touch over the file can help to reboot the configuration, such as
touch tomcat-8.0.18/webapps/ROOT/WEB-INF/classes/dotmarketing-config.properties
Any doubt or question feel free to contact me. Thanks, J
Forgot to add the doc link: https://auth.dotcms.com/docs/latest/changing-dotcms-configuration-properties#Values
Fixed, now we are able to read system and environment variables using s {sys.xxx} and s {env.xxx}, and work fine...
FYI: This changes was implemented just for the dotmarketing.config.properties and dotcms.cluster.properties files....