Support Center
There are several ways in which Zato components can receive and use environment variables. A basic use case is to export them in ~/.bashrc of the "zato" user or to provide them to a starting container's environment. Then, they can be used by your integration services if you access them through os.environ
, which is how environment variables are accessed in Python.
Independently of the above, it is possible for environment variables to dynamically alter configuration of your components. It is also possible for environment variables to be provided in a dedicated file instead of exporting them through ~/.bashrc or Docker.
Each Zato component has one or more configuration files that can be used to fine-tune its operations in a specific environment. For instance, servers have files such as server.conf
or simple-io.conf
and your scheduler has a file called scheduler.conf
.
It is a common need to modify only selected parts of these files, i.e. the majority of it stays as it is but just a few parts, such as TCP ports, should be changed.
One way to do it is custom scripting. For instance, your CI/CD pipeline could use sed
, or a similar tool, to replace the parts that need to be updated. This works, but an alternative to it, built into Zato, is the usage of dynamic environment variables that will take precedence over the values from config files.
Let's have a look at a part of a typical server.conf file. This specific example is responsible for the host and port that a Zato server listens on and, in this case, we would like to change it to listen on "127.0.0.1:17030".
You can achieve it by exporting an environment variable in this format before a server is started:
Let's break down the name of this variable:
Note that the file will not be changed on disk yet the server will recognize the value. That is why these variables are called dynamic - they can point to any key in any .ini configuration file without actually changing the file itself.
Here are a few more examples of overriding the default configuration from .ini files:
Zato_Config_Server_sso__conf_password_expiry="30"
Zato_Config_Server_server__conf_odb_extra="echo=True"
Zato_Config_Server_simple__io__conf_secret_prefix="my_prefix1_, my_prefix2_"
Zato_Config_Scheduler_scheduler__conf_bind_port=31597
Zato_Config_Scheduler_scheduler__conf_server_server_port=17099
Remember that the variables need to be exported before a given component starts. How to do it exactly will depend on how you deploy Zato - it may mean adding them to the ~/.bashrc file of the "zato" user or, if you use Docker Quickstart, it may mean that they need to be provided to a starting container, or you can provide them in a special file, as described below.
When you start a Zato component, you can provide an option called "--env-file" from the command line. This option needs to point to a file with a list of environment variables that the component should make use of.
In this way, you do not need to export the variables through ~/.bashrc or Docker. Instead, you can prepare a dedicated file with environment variables, which in certain situations may be more convenient than having to export them.
For instance, to start a server and make it import environment variables from a file:
Such a file with environment variables is in the format as below:
That is, there is a section called "[env]" and a list of variables and their values follows, with each key/value pair in its own line. There are no limits as to how many keys and values you can place in the file. The file's name needs to be "env.ini" and it can be placed in any directory as long as this specific name is used.
Note that you can still combine this option with Docker. For instance, you can generate the file on your host based on the configuration that is available on host and then map it to the container and start a server with "--env-file" pointing to the file mapped from the host.
The "--env-file" is also available in the enmasse command. Thanks to this, you can reuse the same file with variables when provisioning an environment with enmasse and when Zato components are started.
The contents of the env.ini file, described in the previous section, is re-read by a server each time the file is modified. This lets you hot-deploy environment variables that your services make use of without restarting the servers.
Note, too, that if your configuration files depend on environment variables, the config files have to be redeployed after the env.ini file is hot-deployed.
For instance, let's say you have a config file called "my.ini" with a key of "MyPassword" which points to an environment variable called "Corp_My_Password" and the environment variable is defined in env.ini.
If you modify the password in the env.ini file, and you want for the contents of my.ini to be redeployed, you need to modify my.ini too. You do not need to change its contents, it will suffice if you use the "touch" command, e.g. "touch /path/to/my.ini" will redeploy my.ini with the new password from env.ini.