[systemd-devel] Resolving of a specifier in Environment= and ExecStart=

rtang at tutanota.com rtang at tutanota.com
Wed Feb 3 22:29:57 UTC 2021


Hello,

I've been trying to figure out how the same specifier, particularly %H, is resolved in Environment= and ExecStart=. For that I use a VM with Centos 7 that has systemd v219 (from systemd-219-78.el7_9.2.x86_64 rpm), and a consul-template binary, that starts as systemd service.

The system unit of the latter is quite simple:
...
[Service]
...
Environment=HOSTNAME=%H
ExecStart=/usr/bin/env HOSTNAME=%H /usr/bin/consul-template $CMD_OPTS
...

After the VM has booted that process has the following:

$ hostname
vm-0005

$ sudo systemctl show consul-template | grep -E 'Environment|ExecStart'
ExecStart={ path=/usr/bin/env ; argv[]=/usr/bin/env HOSTNAME=%H /usr/bin/consul-template $CMD_OPTS ; ignore_errors=no ; start_time=[Wed 2021-02-03 21:43:37 UTC] ; stop_time=[n/a] ; pid=1198 ; code=(null) ; status=0/0 }
Environment=HOSTNAME=vm-0004
EnvironmentFile=/etc/sysconfig/consul-template (ignore_errors=no)

$ sudo grep -aoE 'HOSTNAME=[-a-z0-9]+' /proc/$(pidof consul-template)/environ
HOSTNAME=vm-0005

HOSTNAME=vm-0004 was set on a previous VM, that was used to create an image for vm-0005.

>From all of that I have guess that expansion of the same specifier happens at different point in time for Environment= and for ExecStart=. Unfortunately, I could not find any references about that in the documentation. If I edit that system unit or reload systemd, Environment= will have HOSTNAME=vm-0005 value.
Could you please explain how the same specifier is resolved in different directives?

Thank you.

-- 
 Kind regards,
R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210203/65f08b21/attachment.htm>


More information about the systemd-devel mailing list