[systemd-devel] how to depend the service which is triggerred by uevent

Lennart Poettering lennart at poettering.net
Sat Dec 19 10:25:27 UTC 2020


On Do, 24.09.20 17:22, lchina77 (lchina77 at 163.com) wrote:

> Hi, All,
>      I have two services:  service_A and service_B.  The service_A which depends on the tap0 uevent will configure the virtual net,
> while the service_B which depends on the virtual net should run
>      After the service_A,  but  the "After=Service_A" seems to have
>      no effect.

Ordering deps only have an effect of both the origin unit and the
target unit of the dep are in the job queue, as these ordering deps
just control in which order the job queue is run.

In your example, service_A.service is only pulled in by the uevent and
thus if the uevent happens really late service_B.service might already
have run.

Consider adding

        After=sys-devices-virtual-net-tap0.device
        Wants=sys-devices-virtual-net-tap0.device

into service_A.service, and then hook that service unit into
multi-user.target. This then means that the service will be started at
boot, but before it can actually be activated, the tap0 device has to
show up. Key here is that the Wants= pulls the .device unit into the
job queue, and thus can be waited on.

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list