[systemd-devel] Shell expressions in EnvironmentFile

Lennart Poettering lennart at poettering.net
Wed Oct 8 02:47:35 PDT 2014


On Tue, 07.10.14 13:12, Jon Stanley (jonstanley at gmail.com) wrote:

> Since EnvironmentFile in a service isn't sourced by any shell, shell
> expressions in it will obviously not work the way that they did in a
> SysV style script.
> 
> Nor does it seems that the environment gets preserved between
> ExecStartPre (where one could run a script that sets environment
> variables to be later used in the starting of the service) and
> ExecStart, so something like the following won't work:
> 
> [Service]
> ExecStartPre=/something/that/sets/var
> ExecStart=/some/file $var
> 
> Is there some way to get dynamically determined data into the
> environment such that it can be passed to the daemon at start?

In such a case I'd suggest wrapping your daemon invocation in a shell
script, setting the environment variables first, and then using "exec"
to replace the shell process by the actual daemon process.

ExecStartPre= and ExecStart= are run in separate, cleaned up execution
contexts, in particular they do not inherit any environment variables
between each other.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list