<div dir="ltr">Excellent. Thanks for the detailed answers.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 11, 2018 at 11:17 PM Zbigniew Jędrzejewski-Szmek <<a href="mailto:zbyszek@in.waw.pl">zbyszek@in.waw.pl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Jul 11, 2018 at 06:52:12PM -0700, Filipe Brandenburger wrote:<br>
> Hey Daniel!<br>
> <br>
> On Wed, Jul 11, 2018 at 5:16 PM Daniel Wang <<a href="mailto:wonderfly@google.com" target="_blank">wonderfly@google.com</a>> wrote:<br>
> > I have a unit, say foo.service, on my system that's in /usr/lib/systemd/system, but disabled by preset.<br>
> <br>
> Not that it matters, but presets don't really matter here. The unit is<br>
> disabled, period.<br>
> <br>
> > On system boot, it doesn't show as "loaded" per `systemctl --all | grep foo`.<br>
> <br>
> Because there's no reference to it in units systemd sees, so systemd<br>
> doesn't need to load it.<br>
> <br>
> At bootup, systemd will simply start with default.target and then<br>
> recursively load the units it needs.<br>
> <br>
> See this link for more details:<br>
> <a href="https://www.freedesktop.org/software/systemd/man/bootup.html#System%20Manager%20Bootup" rel="noreferrer" target="_blank">https://www.freedesktop.org/software/systemd/man/bootup.html#System%20Manager%20Bootup</a><br>
> <br>
> `systemctl --all` will only show the units in memory, so foo.service<br>
> won't be listed since it's not loaded.<br>
> <br>
> > So if I override it with a file with the same name but under /etc/systemd/system, `systemctl cat foo.service` will show the one under /etc without the need for a `systemctl daemon-reload`.<br>
> <br>
> Yes, because it's not loaded.<br>
> <br>
> > If I create another service unit, bar.service, which has a After= dependency on foo.service, and start bar, foo.service will show as loaded. And then if I try to override it, `systemctl cat foo.service` will print a warning saying a daemon-reload is needed.<br>
> <br>
> Yes. If systemd sees a reference for that unit (even if it's an<br>
> After=), it will need to load it, since it needs to record the<br>
> dependency between the units in the internal memory structures, so it<br>
> needs a reference to the unit, and it loads it to have a complete<br>
> reference to it...<br>
> <br>
> > Nothings seems incorrect, but I have a few questions:<br>
> > - Which units are loaded on-boot and which are not?<br>
> <br>
> Only default.target and recursively any unit referred to by the loaded units.<br>
<br>
What you are saying is all correct, with two very minor nipticks:<br>
- the "default" unit can be overridden with systemd.unit= and 1/2/3, so<br>
it's not always default.target,<br>
- also, there are other units that'll be loaded, for example anything<br>
pulled in by SYSTEMD_WANTS= in udev rules (if the hardware is present),<br>
and .device/.mount/.swap units can also pull other stuff in, and such<br>
units may be created based on the state of the system. So it's<br>
not just the tree starting at the "default" unit, but also a bunch<br>
of other subtree.<br>
<br>
> > - Is the After= dependency alone enough to have systemd load a unit? Are there any other dependency directives that will result in the same effect?<br>
> <br>
> Yes, I believe any reference to units will trigger the unit to be<br>
> loaded. As I mentioned, systemd wants to keep the state in memory, so<br>
> loading the unit will allow it to keep complete state.<br>
> <br>
> An exception (haven't checked it, but I expect it) is references in<br>
> the [Install] section (such as Also=) since those are only used by<br>
> `systemctl enable` and are not really loaded into memory as far as I<br>
> can tell (but I might be wrong here, and these might trigger the unit<br>
> to load as well.)<br>
Yes, anything in [Install] doesn't matter (except that after the<br>
installation is done, the symlinks that are created do matter).<br>
<br>
Zbyszek<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Best,</div><div>Daniel</div></div></div>