Systemd, a multi-line variable in the environment file where a new line is important

I use systemd on debian jessie to control the service into which I load environment variables via EnvironmentFile=/etc/default/myservice

in this file I have a variable that is a public key

  JWT_PUB_KEY="-----BEGIN FOO BAR KEY----- MIIBgjAcBgoqhkiG9w0BDAEDMA4ECKZesfWLQOiDAgID6ASCAWBu7izm8N4V 2puRO/Mdt+Y8ceywxiC0cE57nrbmvaTSvBwTg9b/xyd8YC6QK7lrhC9Njgp/ ... -----END FOO BAR KEY-----" 

Putting it like this, it will not like systemd, which reports an error (although the execution of source in bash of the same file works correctly)

the systemd report documentation that you can have a multi-line variable ending each file with \ but concatenate each line (so that my program gets an integer under one line, which is not a more valid public key)

Is there a known way to keep the end of a line? without resorting to hacking, how to put \n which they "interpret" in my application code?

+7
systemd
source share
2 answers

As you suspected, Systemd accepts \n definitions of internal environment variables. You don’t need to do any special parsing, just add the appropriate \n where you need them and avoid the actual translation lines. Systemd needs to handle the rest and turn them into a literal. In your case, it will look something like this:

 JWT_PUB_KEY="-----BEGIN FOO BAR KEY-----\n\ MIIBgjAcBgoqhkiG9w0BDAEDMA4ECKZesfWLQOiDAgID6ASCAWBu7izm8N4V\n\ 2puRO/Mdt+Y8ceywxiC0cE57nrbmvaTSvBwTg9b/xyd8YC6QK7lrhC9Njgp/\n\ ...\n\ -----END FOO BAR KEY-----" 
+1
source share

You do not need to interpret (parse?) The newline characters at your end, which should happen automatically, as described here , that adding '\ n' at the end of each line should do the trick.

0
source share

All Articles