I want to specify an Environment
systemd
directive containing =
, e.g.
Environment=CATALINA_OPTS=-Dappserver.home=/var/lib/archiva/apache-tomcat-current -Dappserver.base=/var/lib/archiva/apache-tomcat-current
and get the error
[/lib/systemd/system/archiva.service:10] Invalid environment assignment, ignoring: CATALINA_OPTS=-Dappserver.home\=/var/lib/archiva/apache
in journalctl -xe
. I tried to quote with "
and '
and to escape =
with \
without success. This seems undocumented.
I think your problem is due the space in the environment variable's contents. Looking at the examples from the systemd docs, an assignment should be a single string:
I tested this with the following service (note the quotes around the entire assignment):
And got the desired output in
journalctl
:Of course, it would be simpler to use
EnvironmentFile
instead. Replacing theEnvironment
with the following gave the same desired result:Where
/tmp/foo
contained (note the lack of quotes):Alternative solution
"C escapes supported in command lines and environment variables"
https://www.freedesktop.org/software/systemd/man/systemd.service.html
In addition to what the accepted answer says, if you put your environment variables into a drop-in file, then you need to use the following syntax to make sure they are not all treated as one argument to your program:
env.conf drop-in file
unit.service
I don't know why using just
$ENV_NAME
worked for me, and${ENV_NAME}
didn't, and I couldn't find anything documenting this difference. All I can say is that$ENV_NAME
syntax worked to treat each argument in the variable which is separated by space, as distinct arguments, whereas the${ENV_NAME}
, treated them all as one argument.Maybe using
echo
is not the best way to tell this difference. I suggest anyone looking to test it to use something like/usr/bin/printf "%s\n" ${ENV_NAME}
vs/usr/bin/printf "%s\n" $ENV_NAME
, and see what they get.EDIT
I found the documentation, thanks to another answer: