<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 17, 2022 at 6:45 PM Lennart Poettering <<a href="mailto:lennart@poettering.net">lennart@poettering.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fr, 16.09.22 10:10, Antonio Murdaca (<a href="mailto:runcom@redhat.com" target="_blank">runcom@redhat.com</a>) wrote:<br>
<br>
> Hi, following<br>
> <a href="https://systemd.io/AUTOMATIC_BOOT_ASSESSMENT/#how-to-adapt-this-scheme-to-other-setups" rel="noreferrer" target="_blank">https://systemd.io/AUTOMATIC_BOOT_ASSESSMENT/#how-to-adapt-this-scheme-to-other-setups</a><br>
> I've been experimenting on a fedora system<br>
> with systemd-boot-check-no-failures.service and the ability to have<br>
> services run "after" boot-complete.target. The basic use case would just to<br>
> have something that checks services are up and running, reach boot-complete<br>
> if they are, and start other services afterwards.<br>
> I've taken from that blog this piece specifically:<br>
> ```<br>
> To support additional components that shall only run on boot success,<br>
> simply wrap them in a unit and order them after boot-complete.target,<br>
> pulling it in.<br>
> ```<br>
> So I've done the following with an example service and by enabling :<br>
><br>
> # cat /etc/systemd/system/test.service<br>
> [Unit]<br>
> Description="Order after boot-complete.target, pulling it in"<br>
> After=boot-complete.target<br>
> Requires=boot-complete.target<br>
><br>
> [Service]<br>
> Type=oneshot<br>
> ExecStart=/usr/bin/echo "Additional component that shall only run on boot<br>
> success"<br>
> RemainAfterExit=yes<br>
><br>
> [Install]<br>
> WantedBy=default.target<br>
><br>
> # systemctl enable test.service systemd-boot-check-no-failures.service<br>
> Created symlink /etc/systemd/system/default.target.wants/test.service →<br>
> /etc/systemd/system/test.service.<br>
> Created symlink<br>
> /etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service<br>
> → /usr/lib/systemd/system/systemd-boot-check-no-failures.service.<br>
><br>
> # systemctl reboot<br>
><br>
> Unfortunately, the above results in:<br>
><br>
> systemd[1]: multi-user.target: Found ordering cycle on test.service/start<br>
> systemd[1]: multi-user.target: Found dependency on<br>
> boot-complete.target/start<br>
> systemd[1]: multi-user.target: Found dependency on<br>
> systemd-boot-check-no-failures.service/start<br>
> systemd[1]: multi-user.target: Found dependency on multi-user.target/start<br>
> systemd[1]: multi-user.target: Job test.service/start deleted to break<br>
> ordering cycle starting with multi-user.target/start<br>
><br>
> so what's the correct way to perform the mentioned "order [units] after<br>
> boot-complete.target", if they cannot be pulled in through the usual<br>
> default/multi-user targets? If I add DefaultDependencies=no to test.service<br>
> it now appears to work w/o the dependency cycle.<br>
<br>
It should suffice adding After=multi-user.target to your service.<br>
<br>
The things is that systemd-boot-check-no-failures.service runs late,<br>
after the startup transaction is done to check if everything<br>
succeeded. But now you want to run something more, so by default<br>
s-b-c-n-f.s would also want to run after that, to know if it<br>
succeeded. But htat of course makes little sense: the output of<br>
your service cannot be part of the input of s-b-c-n-f.s if your<br>
service should run after s-b-c-n-f.s!<br>
<br>
So, my recommended fix: add After=multi-user.target to your<br>
service. Note that systemd handling of .wants/ works like this:<br>
<br>
1. add Wants= type dep<br>
2. if no After=/Before= dep is set, then also add Before=<br>
<br>
This means, that just adding an explicit After=multi-user.target to<br>
your service means rule #2 won't take effect anymore.<br>
<br>
With that in place things should just work (untested, but afaics), as<br>
it means s-b-c-n-f.s can run after multi-user.target, and then<br>
boot-complete.target after that, and then finally your service.<br>
<br>
Does that make sense?<br></blockquote><div><br></div><div>that works and makes total sense! thanks! I'd enhance the documentation around that as it wasn't immediately clear to me that adding After would result in that though!</div><div>thanks!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Berlin<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Antonio (runcom) Murdaca<br>Principal Software Engineer</div><div dir="ltr"><span style="color:rgb(0,0,0)">B056 8311 87B3 DDEB 25B5 01AF CC5C 9A81 EDCA D821</span></div></div></div></div></div></div></div></div></div>