Do systemd unit files support preserving existing environment variables?

(Something similar to sudo -E?)

Not referring to Environment= or EnvironmentFile= here.

It would be be useful if systemd could for example leave the DPKG_MAINTSCRIPT_PACKAGE environment variable intact. Then the service had a chance to determine wheter it was restarted as part of a an upgrade (apt-get / dpkg set the DPKG_MAINTSCRIPT_PACKAGEenvironment variable.) vs manually/at boot.


That would not make sense because the started service is not a child of the process which caused the start. systemctl connects to the running systemd and makes it start the processes. So even if the environment was preserved (maybe it even is...) then it would be systemd's environment that gets inherited. And that does not contain the entries you want.

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.