Custom Environment Variables
Environment variables act as handy placeholders, allowing you to stash commonly used parameter values or strings. This spares you the hassle of repeatedly inputting them into your code. The platform comes preloaded with default environment variables, which you can readily employ in your application’s code. Moreover, you can tweak these variables before node creation to tailor your setup, enhancing your platform experience with added convenience.
In this guide, we’ll explain the typical methods for including your custom variables for any node on the platform.
- Via a dedicated variables section of the dashboard
- Using the shell configuration files
- Through the variables.conf file (for Java only)
Customize Environment Variables via UI
1. Move your cursor over the node group on the dashboard, then open up the Additionally list and choose the Variables option.
2. In the open window, you can tweak a set of environment settings according to what you need. Just use the buttons in the toolbar.
Remember to Apply the changes you’ve made.
Set Up Environment Variables via Shell Configs
You can customize your variables using the shell configuration files:
- ~/.bash_profile is run only when you log in through the console.
- ~/.bashrc runs every time a new bash instance is opened.
To assist you in managing these files, the platform automatically adds the sources of the .bashrc configuration to the .bash_profile. This way, you can define custom variables using just the former file.
1. Connect to your container using SSH. You can do this by utilizing the built-in Web SSH client, for instance.
2. To set up your custom variables, simply open or modify the .bashrc file located in your home directory using the following format:
export {var_name}= {var_value}
Where
{var_name} refers to the name of the variable you want to define, while {var_value} represents the value assigned to that variable.
3. From now on, every time you start a new bash session, it will come loaded with your personalized variables. If you want the changes to take effect immediately in your current session, simply refresh the sources using the command below. Then, double-check to ensure the new variables are accessible:
source ~/.bashrc
echo $ {var_name}
As you can see in the above screen capture, the modifications were implemented successfully.
Adjust Java Environment Variables via Configuration Manager
The basic process outlined below is the same for all Java application servers managed by the platform.
1. To access the file manager for your application server, simply click on the “Config” button.
2. Go to the open tab and find the variables.conf file in one of these places:
- Tomcat, TomEE – /opt/tomcat/conf/variables.conf
- Jetty – /opt/jetty/etc/variables.conf
- Spring Boot – /opt/shared/conf/variables.conf
- GlassFish – /opt/glassfish/glassfish/domains/domain1/config/variables.conf
- Payara – /opt/payara/glassfish/domains/domain1/config/variables.conf
- WildFly – /opt/wildfly/conf/variables.conf
3. Here, you can input your variables (make sure each one is separated by a space or starts on a new line) or tweak Java settings for your application. For instance:
- Dvar1=value1 -Dvar2=value2
- Dmy.var3=/my/value
Note: Alternatively, certain application servers like GlassFish, Payara, and WildFly come with an admin panel. This panel enables users to add JVM options and customize variables as needed.
Make sure you remember to Save the changes you’ve made to the settings.
4. To make sure the changes take effect, you’ll need to Restart the nodes on your application server.
5. In your Java code, you can use the System.getProperty(“your_variable”) method to access the new variables and assign their values to the required arguments. For instance:
- String var1 = System.getProperty(“var1”);
- String var2 = System.getProperty(“var2”);
- String var3 = System.getProperty(“my.var3”)
You can now modify your application code using these new variables.