>>> Lennart Poettering <lennart@xxxxxxxxxxxxxx> schrieb am 19.04.2022 um 11:41 in Nachricht <Yl6DumuBrCyJzmYR@gardel-login>: > On Di, 19.04.22 11:14, Alessio Igor Bogani (alessio.bogani@xxxxxxxxxx) wrote: > >> Dear systemd developers, >> >> Sorry for my very bad english. > > Not bad at all. > >> We use the hostname provided by DHCP to start the right subset of our >> applications on each of our machines (in other words the transient >> hostname is used as predictable machine identifier). >> >> Make it works on the ancient SysV is straightforward but I can't find >> a (reasonable) way to achieve the same goal with systemd. We already >> use both "Requires" and "After" with "network‑online.target >> nss‑lookup.target" into our units but it isn't enough. When our units >> start they obtain "localhost" from %H specifier. We don't find a way >> to wait for (transient) hostname to be configured. The only solution >> that it seems to work is to replace our binary in ExecStart with a >> script which make a busy‑loop until `hostname` output doesn't differ >> from "localhost". >> >> Is there a better way? > > First of all: % specifiers (including %H) are resolved at the moment > the unit files are *loaded*, i.e. typically at earliest boot, long That's quite some surprise: I thought they are evaluated when they are executed (as in shell scripts). Is there a way to "reload" a specific unit file? > before they are actually *started*. Thus, if you change the hostname > and want %H to resolve to that, you need to issue a reload at the > right moment, i.e. issue `systemctl daemon‑reload` once the hostname > is acquired. > > If your hostname is set via DHCP you need to wait for DHCP to be > acquired. How that's done, depends on the networking solution you > use. If you use systemd‑networkd, then the > sytemd‑network‑wait‑online.service is what you want to use. If you > enable that then network‑online.target should be the point where DHCP > is acquired and thus also the hostname in effect. > > Lennart > > ‑‑ > Lennart Poettering, Berlin