[systemd-devel] the intended behavior of EnvironmentFile

Igor Bukanov igor at mir2.org
Tue Jun 26 22:33:27 UTC 2018


Hi,

the man page for systemd.exec tells that for EnvironmentFile:

The files listed with this directive will be read shortly before the
process is executed (more specifically, after all processes from a
previous unit state terminated. This means you can generate these
files in one unit state, and read it with this option in the next).

Yet for a service unit with, for example,  several ExecStartPost
commands the environment files are parsed before each invocation of
ExecStartPost even if there is no change in the state of the unit and
not all processes are terminated. I.e. when starting a service like:

[Service]
Type=oneshot
EnvironmentFile=-/run/foo.env
ExecStart=/bin/sh -c 'echo FOO=BAR > /run/foo.env'
ExecStartPost=/bin/sh -c 'echo $FOO; echo FOO=BAR2 > /run/foo.env; sleep 5&'
ExecStartPost=/bin/sh -c 'echo $FOO; echo FOO=BAR3 > /run/foo.env'
ExecStartPost=/bin/sh -c 'echo $FOO'

the log contains BAR BAR2 BAR3 even if there no change of the state in
the unit state between ExecStartPost and the last ExecStartPost runs
when the sleep command still runs.

It is just poor wording in the documentation, isn't it? I.e. the
intended behavior is that the environment file are parsed before
executing any Exec* line irrespective of the unit state, right?

Regards, Igor


More information about the systemd-devel mailing list