systemd, EnvironmentFile, re-using variables - how?

Unfortunately that file you have is actually a shell script. In the past, most init systems/scripts have interpreted files which provide environment variables by using the shell, so you could get away with doing shell things in them. Systemd however does not do this. The environment file is truly an environment file, not a script. This is documented in the systemd.exec man page:

Variable expansion is not performed inside the strings, however, specifier expansion is possible. The $ character has no special meaning.

Therefore you have 2 options.

  1. Expand out all your variables manually. Meaning use CATALINA_BASE=/d01/tomcat/prod/xyz/1.

  2. Evaluate the file with the shell:
    ExecStart=/bin/bash -ac '. /path/to/env_file; exec /path/to/program'


Do I need to make one long hard to read statement?

No

A line ending with a backslash will be concatenated with the following one, allowing multiline variable definitions.


You could use bash to expand your variables.

Environment file:

BLA=bla
BLABLA=${BLA}${BLA}

Use bash -c to execute the command:

ExecStart=/usr/bin/bash -c 'echo ${BLA} .. ${BLABLA}'

Output:

bash[4771]: bla .. blabla