[systemd-devel] Issues with Service Dependencies in Systemd

Mantas Mikulėnas grawity at gmail.com
Wed May 22 06:21:23 UTC 2024


On Tue, May 21, 2024 at 11:47 PM Robert Landers <landers.robert at gmail.com>
wrote:

> Hello hello,
>
> I'm encountering an issue with Systemd service dependencies that I
> can't seem to resolve despite following the documentation. Either
> there's a misunderstanding on my part or there's a potential bug.
>
> 1. I cannot modify a specific service (immutable.service) because it's
> generated dynamically by a tool which I also cannot modify.
>

A service may consist of multiple config files – even if you cannot modify
/etc/…/immutable.service itself, you can still extend it by creating
/etc/…/immutable.service.d/foo.conf (e.g. using `systemctl edit immutable`)
which lets you add any properties (or reset/remove many of them); and
technically, you're already doing something like that using your WantedBy=
and RequiredBy= settings – they're both implemented by extending the
specified service with Wants/Requires without actually modifying its file.


> 2. I need to create a service (after-reboot.service) that runs after
> the network is completely up and running and before immutable.service.
> 3. I need to prevent immutable.service from starting if
> after-reboot.service fails to start.
>

Use the "drop-in" mechanism to extend immutable.service with:

# /etc/systemd/system/immutable.service.d/special.conf
[Unit]
After=after-reboot.service
Requires=after-reboot.service
# or Requisite=, or AssertSomething=, or whatever suits

[Install]
> WantedBy=multi-user.target
> RequiredBy=immutable.service
>

This should work, but all of [Install] is only re-applied when you
`systemctl [re]enable after-reboot`, so make sure you have done that.
(That's the reason it's under [Install] and not under [Unit].)

But since it's done to a .service, it doesn't imply any Before/After (if I
remember correctly, the Wants-implies-After is .target-specific magic), so
that may be what makes RequiredBy= insufficient. Use a .conf to add both
Requires *and* After to immutable.service.


-- 
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20240522/2cbd3d32/attachment.htm>


More information about the systemd-devel mailing list