Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-21 Thread Kenneth Porter

On 4/20/2022 1:09 PM, Alessio Igor Bogani wrote:

# ExecStart=/usr/bin/Starter %H
ExecStart=/bin/sh -c 'sleep 1; exec /usr/bin/Starter `hostname`'


Is there a significant advantage to using the systemd macro over the 
backtick operator applied to the hostname program? Is the overhead of a 
spawned process really that expensive in this usage?


If you're scrabbling for CPU cycles, you might be better off writing 
everything in C and using low-level kernel APIs. But I suspect that's 
not the case here.





Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Dan Nicholson
On Wed, Apr 20, 2022 at 2:10 PM Alessio Igor Bogani
 wrote:
>
> Hi Lennart,
>
> On Wed, 20 Apr 2022 at 16:47, Lennart Poettering  
> 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.


Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Alessio Igor Bogani
Hi Lennart,

On Wed, 20 Apr 2022 at 16:47, Lennart Poettering  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

> What doesn't work precisely?

The %H specifier in the commented ExecStart always returns
"localhost". The following ExecStart is my workaround to have the
hostname provided by DHCP (in the first version it was a while loop
but a sleep works anyway and make things less convoluted).

Ciao,
Alessio


Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Luca Boccassi
Be very careful about inserting daemon-reload in the boot process,
especially early. At best it will cause slow-downs, at worst lock ups.

On Wed, 2022-04-20 at 13:18 +, Sietse van Zanen wrote:
> Why not add:
> 
> ExecStartPost=systemctl daemon-reload
> 
> to systemd-networkd-wait-online.service?
> 
> 
> -Sietse
> 
> 
> From: systemd-devel  on behalf 
> of Alessio Igor Bogani 
> Sent: Wednesday, April 20, 2022 12:54:11 PM
> To: Lennart Poettering
> Cc: systemd-devel@lists.freedesktop.org
> Subject: Re: [systemd-devel] Waiting for (transient) hostname configuration
> 
> Hi Lennart,
> 
> On Tue, 19 Apr 2022 at 11:41, Lennart Poettering  
> wrote:
> [...]
> > the unit files are *loaded*, i.e. typically at earliest boot, long
> > before they are actually *started*. Thus, if you change the hostname
> 
> I understand now. It was the evaluation time of the specifier that I
> have missed. I have just realized that my question was dumb, sorry for
> that.
> 
> [...]
> > 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.
> 
> I use systemd-networkd and systemd-networkd-wait-online is enabled but
> unfortunately it doesn't work anyway. I have also tried to request
> systemd to execute systemd-hostnamed "Before = nss-lookup.target" (*)
> without success.
> I left the little shell script inside to ExecStart to solve my problem
> waiting for a better solution.
> 
> Thanks Lennart for time, consideration and kindness.
> 
> Have a nice and safe day!
> 
> Ciao,
> Alessio
> 
> (*) All my Units use "After = network-online.target nss-lookup.target"
> 
> 



signature.asc
Description: This is a digitally signed message part


Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Lennart Poettering
On Mi, 20.04.22 12:54, Alessio Igor Bogani (alessio.bog...@elettra.eu) wrote:

> > the unit files are *loaded*, i.e. typically at earliest boot, long
> > before they are actually *started*. Thus, if you change the hostname
>
> I understand now. It was the evaluation time of the specifier that I
> have missed. I have just realized that my question was dumb, sorry for
> that.

Not at all.

> > 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.
>
> I use systemd-networkd and systemd-networkd-wait-online is enabled but
> unfortunately it doesn't work anyway.

What doesn't work precisely?

Lennart

--
Lennart Poettering, Berlin


Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Sietse van Zanen
Why not add:

ExecStartPost=systemctl daemon-reload

to systemd-networkd-wait-online.service?


-Sietse


From: systemd-devel  on behalf of 
Alessio Igor Bogani 
Sent: Wednesday, April 20, 2022 12:54:11 PM
To: Lennart Poettering
Cc: systemd-devel@lists.freedesktop.org
Subject: Re: [systemd-devel] Waiting for (transient) hostname configuration

Hi Lennart,

On Tue, 19 Apr 2022 at 11:41, Lennart Poettering  wrote:
[...]
> the unit files are *loaded*, i.e. typically at earliest boot, long
> before they are actually *started*. Thus, if you change the hostname

I understand now. It was the evaluation time of the specifier that I
have missed. I have just realized that my question was dumb, sorry for
that.

[...]
> 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.

I use systemd-networkd and systemd-networkd-wait-online is enabled but
unfortunately it doesn't work anyway. I have also tried to request
systemd to execute systemd-hostnamed "Before = nss-lookup.target" (*)
without success.
I left the little shell script inside to ExecStart to solve my problem
waiting for a better solution.

Thanks Lennart for time, consideration and kindness.

Have a nice and safe day!

Ciao,
Alessio

(*) All my Units use "After = network-online.target nss-lookup.target"




Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Alessio Igor Bogani
Hi Lennart,

On Tue, 19 Apr 2022 at 11:41, Lennart Poettering  wrote:
[...]
> the unit files are *loaded*, i.e. typically at earliest boot, long
> before they are actually *started*. Thus, if you change the hostname

I understand now. It was the evaluation time of the specifier that I
have missed. I have just realized that my question was dumb, sorry for
that.

[...]
> 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.

I use systemd-networkd and systemd-networkd-wait-online is enabled but
unfortunately it doesn't work anyway. I have also tried to request
systemd to execute systemd-hostnamed "Before = nss-lookup.target" (*)
without success.
I left the little shell script inside to ExecStart to solve my problem
waiting for a better solution.

Thanks Lennart for time, consideration and kindness.

Have a nice and safe day!

Ciao,
Alessio

(*) All my Units use "After = network-online.target nss-lookup.target"


Re: [systemd-devel] Antw: [EXT] Re: [systemd‑devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Lennart Poettering
On Mi, 20.04.22 08:16, Ulrich Windl (ulrich.wi...@rz.uni-regensburg.de) wrote:

> >> 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?

No. You can only reload them all at once, via "systemctl daemon-reload".

Lennart

--
Lennart Poettering, Berlin


[systemd-devel] Antw: [EXT] Re: [systemd‑devel] Waiting for (transient) hostname configuration

2022-04-20 Thread Ulrich Windl
>>> Lennart Poettering  schrieb am 19.04.2022 um 11:41
in
Nachricht :
> On Di, 19.04.22 11:14, Alessio Igor Bogani (alessio.bog...@elettra.eu)
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





Re: [systemd-devel] Waiting for (transient) hostname configuration

2022-04-19 Thread Lennart Poettering
On Di, 19.04.22 11:14, Alessio Igor Bogani (alessio.bog...@elettra.eu) 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
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