3

I've tried to set following in my systemd's service file

Environment=SETTINGS=\'{"a"=1}\'

But seems that both the single quotes are been removed, so I get {"a"=1} as the value for the environment variable SETTINGS

How I can set that correctly?

5
  • To be clear: Do you actually want the single quotes to be present in the environment value? Aug 6 '14 at 4:58
  • Unfortunately, I currently need to set something like METEOR_SETTINGS='{"public":{"ga":{"account":"UA-xxxxxx-2"}}}'
    – waitingkuo
    Aug 6 '14 at 5:27
  • 1
    I think maybe you can do this in an EnvironmentFile with appropriate escaping. But you're deep into undocumented territory here. Though, for something like this you really ought to be using an EnvironmentFile regardless. Aug 6 '14 at 5:35
  • 1
    After reflecting on this a while, I think you have actually found a bug in systemd. This smells like a parser running twice on the same input. Aug 6 '14 at 5:54
  • I've summit it to their bug tracker
    – waitingkuo
    Aug 6 '14 at 9:29
1

This works for me:

$ cat /run/user/1000/systemd/user/envtest3.service
[Service]
Environment=SETTINGS=\'{"a"=1}\'
Environment=SETTINGS2='{"a"=1}'

Type=oneshot
ExecStart=/bin/env

then

$ systemctl --user start envtest3.service
$ journalctl --user -n 2
-- Logs begin at wto 2014-05-27 15:33:38 EDT, end at sob 2014-10-04 11:44:13 EDT. --
paź 04 11:44:13 fedora21 env[27607]: SETTINGS='{"a"=1}'
paź 04 11:44:13 fedora21 env[27607]: SETTINGS2='{"a"=1}'

As you can see, the variables get set properly.

You can also use those variables in the unit itself:

...
ExecStart=/bin/echo ${SETTINGS} ${SETTINGS2}
ExecStart=/bin/echo $SETTINGS $SETTINGS2

and there's surprising thing here:

paź 04 14:27:50 fedora21-amd64 echo[30304]: '{"a"=1}' '{"a"=1}'
paź 04 14:27:50 fedora21-amd64 echo[30306]: {"a"=1} {"a"=1}

The expansion with braces does not strip the quotes, but the other one does. I'm not sure if this is a bug, or not. The manpage says "split at whitespace".

Edit: I'm runninng latest git (v216-456-gba58907547).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.