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?
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).
METEOR_SETTINGS='{"public":{"ga":{"account":"UA-xxxxxx-2"}}}'
EnvironmentFile
with appropriate escaping. But you're deep into undocumented territory here. Though, for something like this you really ought to be using anEnvironmentFile
regardless.