[systemd-devel] Waiting for (transient) hostname configuration
Dan Nicholson
dbn at endlessos.org
Wed Apr 20 20:52:38 UTC 2022
On Wed, Apr 20, 2022 at 2:10 PM Alessio Igor Bogani
<alessio.bogani at elettra.eu> wrote:
>
> Hi Lennart,
>
> On Wed, 20 Apr 2022 at 16:47, Lennart Poettering <lennart at poettering.net> wrote:
> [...]
> > > I use systemd-networkd and systemd-networkd-wait-online is enabled but
> > > unfortunately it doesn't work anyway.
>
> If you don't mind I show you one of my Unit files:
>
> [Unit]
> Description=Tango Starter service
> Requires=network-online.target nss-lookup.target
> Wants=tangorc.service
> After=network-online.target tangorc.service nss-lookup.target
> Conflicts=shutdown.target
> RequiresMountsFor=/runtime
>
> [Service]
> User=controls
> Group=controls
> # ExecStart=/usr/bin/Starter %H
> ExecStart=/bin/sh -c 'sleep 1; exec /usr/bin/Starter `hostname`'
> KillMode=process
> RestartSec=5s
> Restart=on-failure
>
> [Install]
> WantedBy=multi-user.target
I think the part you may have missed is you need something to run
systemctl daemon-reload after networking is available but before your
units are started. There are a couple ways to do that. One is to add
your own unit that has After=network-online.target and simply has
ExecStart=/bin/systemctl daemon-reload. Then you're other real units
like the one above would have Requires and After on the unit that runs
daemon-reload.
Another way suggested by Sietse would be to add a drop-in for
systemd-networkd-wait-online.service that adds
ExecStartPost=/bin/systemctl daemon-reload. Since that's already going
to run before network-online.target, none of your other units have to
change.
More information about the systemd-devel
mailing list