Skip to content

Setting Environment Variables in Descriptors

2 min read

2 min read

2 min read

2 min read

2 min read

2 min read

2 min read

2 min read

2 min read

Server descriptors and IceBox descriptors may specify environment variables that the node will define when starting a server. An environment variable definition uses the familiar name=value syntax, and you can also refer to other environment variables within the value. The exact syntax for variable references depends on the platform on which the server's descriptor is deployed.

On Linux and macOS, the node expands references written in Bourne shell syntax:

LD_LIBRARY_PATH=/opt/Ice/lib:$LD_LIBRARY_PATH

On a Windows platform, the syntax uses the conventional style:

PATH=C:\Ice\lib;%PATH%

In XML, the env element supplies a definition for an environment variable:

XML
<node name="LinuxBox">
<server id="UnixServer" exe="/opt/app/bin/server" ...>
<env>LD_LIBRARY_PATH=/opt/Ice/lib:$LD_LIBRARY_PATH</env>
...
</server>
</node>
<node name="WindowsBox">
<server id="WindowsServer" exe="C:/app/bin/server.exe" ...>
<env>PATH=C:\Ice\lib;%PATH%</env>
...
</server>
</node>

If a value refers to an environment variable that is not defined, the reference is substituted with an empty string.

Environment variable definitions may also refer to descriptor variables and template parameters:

XML
<node name="LinuxBox">
<variable name="appdir" value="/opt/app"/>
<server id="LinuxServer" exe="${appdir}/bin/server" ...>
<env>PATH=${appdir}/bin:$PATH</env>
...
</server>
</node>

On Linux and macOS, an environment variable VAR can be referenced as $VAR or ${VAR}. IceGrid interprets ${VAR} as a reference to a descriptor variable or parameter; to refer to an environment variable with this syntax, escape it as $${VAR}:

XML
<node name="LinuxBox">
<variable name="appdir" value="/opt/app"/>
<server id="LinuxServer" exe="${appdir}/bin/server" ...>
<env>PATH=${appdir}/bin:$${PATH}</env>
...
</server>
</node>

IceGrid removes the leading $ from $${PATH} when it performs substitution; the node then expands ${PATH} using its environment.