<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div>Hello,<br></div><div><br></div><div>I've been trying to figure out how the same specifier, particularly <span class="font" style="font-family: monospace, sans-serif;">%H</span>, is resolved in <span class="font" style="font-family: monospace, sans-serif;">Environment=</span> and <span class="font" style="font-family: monospace, sans-serif;">ExecStart=</span>. 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.<br></div><div><br></div><div>The system unit of the latter is quite simple:<br></div><div><span class="font" style="font-family: monospace, sans-serif;">...<br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">[Service]<br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">...<br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">Environment=HOSTNAME=%H<br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">ExecStart=/usr/bin/env HOSTNAME=%H /usr/bin/consul-template $CMD_OPTS<br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">...</span><br></div><div><br></div><div>After the VM has booted that process has the following:<br></div><div><br></div><div><span class="font" style="font-family: monospace, sans-serif;">$ hostname</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">vm-0005</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">$ sudo systemctl show consul-template | grep -E 'Environment|ExecStart'</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">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 }</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">Environment=HOSTNAME=vm-0004</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">EnvironmentFile=/etc/sysconfig/consul-template (ignore_errors=no)</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">$ sudo grep -aoE 'HOSTNAME=[-a-z0-9]+' /proc/$(pidof consul-template)/environ</span><span class="font" style="font-family: monospace, sans-serif;"><br></span></div><div><span class="font" style="font-family: monospace, sans-serif;">HOSTNAME=vm-0005</span><br></div><div><br></div><div><span class="font" style="font-family: monospace, sans-serif;">HOSTNAME=vm-0004</span> was set on a previous VM, that was used to create an image for vm-0005.<br></div><div><br></div><div>From all of that I have guess that expansion of the same specifier happens at different point in time for <span class="font" style="font-family: monospace, sans-serif;">Environment=</span> and for <span class="font" style="font-family: monospace, sans-serif;">ExecStart=</span>. Unfortunately, I could not find any references about that in the documentation. If I edit that system unit or reload systemd, <span class="font" style="font-family: monospace, sans-serif;">Environment= </span>will have <span class="font" style="font-family: monospace, sans-serif;">HOSTNAME=vm-0005</span> value.<br></div><div>Could you please explain how the same specifier is resolved in different directives?<br></div><div><br></div><div>Thank you.<br></div><div><br></div><div>-- <br></div><div> Kind regards,<br></div><div>R<br></div> </body>
</html>