<div dir="ltr">Well explained. Thanks Lennart.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 24, 2018 at 12:11 PM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mi, 24.01.18 10:33, Daniel Wang (<a href="mailto:wonderfly@google.com">wonderfly@google.com</a>) wrote:<br>
<br>
> I have cluster of 100s of nodes with systemd-232. To work-around a recently<br>
> discovered bug in systemd (<a href="https://github.com/systemd/systemd/issues/7798" rel="noreferrer" target="_blank">https://github.com/systemd/<wbr>systemd/issues/7798</a>),<br>
> I want to deploy a timer to all my nodes that will check the number of<br>
> units and run `systemctl daemon-reload` once a certain threshold is hit<br>
> (100K for example).<br>
><br>
> I am asked whether I could have the timer skip the check and blindly run<br>
> `systemctl daemon-reload` at every invocation. Would there be any problem<br>
> with that? IIUC, reloading the daemon is a rather "safe" operation?<br>
<br>
</span>When you have unit files that have multiple ExecXYZ= lines of the same<br>
type (such as a Type=oneshot file with three ExecStart= lines), and<br>
you change these lines between reloads then there's the conceptual<br>
problem that it's not clear where systemd shall continue execution<br>
next: the line it currently executes might have been removed or<br>
changed, and there's no clear rule how to recognize in the changed<br>
version at which line we are now, and which one to start next.<br>
<br>
Example:<br>
<br>
Consider a service:<br>
<br>
[Service]<br>
ExecStart=/usr/bin/one<br>
ExecStart=/usr/bin/two<br>
ExecStart=/usr/bin/three<br>
<br>
Now you change it to:<br>
<br>
[Service]<br>
ExecStart=/usr/bin/one<br>
ExecStart=/usr/bin/foo<br>
ExecStart=/usr/bin/qux<br>
ExecStart=/usr/bin/three<br>
<br>
And reload, while the process "two" was running. What should happen<br>
now? Should systemd now run "foo"? or maybe "quux"? Or "three"?<br>
<br>
Now, it's not just about replacing lines fully or adding and removing<br>
some, but also just slightly altering the command line arguments.<br>
<br>
Because it isn#t conceptually clear what to run next in such a case<br>
versions of systemd before 233 had the simple rule: "we start from the<br>
beginning" again, after a reload we'd always start the first of the<br>
ExecStart= again.<br>
<br>
In 233 this was improved a bit. There we'll try to find the right line<br>
to continue with by searching for it literally, and falling back to a<br>
simple index-based approach to this if we can't find it literlal. It's<br>
making the best from a bad situation, and makes things fully reliable<br>
when the unit file didn't change at least.<br>
<br>
The above is the major caveat when reloading the daemon in full: if<br>
you have unit files with multiple ExecXYZ= lines of the same type and<br>
you keep reloading systemdyou are in trouble in < 233, and on >= 233<br>
you are still possibly in trouble if you modify them in between but<br>
are safe if you just keep them as-is.<br>
<br>
The relevant PR is <a href="https://github.com/systemd/systemd/pull/5354" rel="noreferrer" target="_blank">https://github.com/systemd/<wbr>systemd/pull/5354</a><br>
<br>
Another caveat is that because all state is flushed out and then<br>
rebuild in full the operation is relatively heavy if you have tons of<br>
units.<br>
<br>
Other than the above doing reloads should be safe and not lose state.<br>
<span class="HOEnZb"><font color="#888888"><br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Red Hat<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Best,</div><div>Daniel</div></div></div>
</div>