Make systemd service wait for a device, generically

3

Currently, I am using the following config to make sure that my display manager waits to start until after the DRM driver is loaded (otherwise X.org cannot start):

udev rule:

ACTION=="add", SUBSYSTEM=="drm", KERNEL=="card0", TAG+="systemd"

systemd service override:

[Unit]
Requires=sys-devices-pci0000:00-0000:00:01.0-0000:01:00.0-drm-card0.device
After=sys-devices-pci0000:00-0000:00:01.0-0000:01:00.0-drm-card0.device

This gets the job done, but it seems fragile.

Is it possible to shorten the Requires= and After= lines to refer to the DRM device generically, without using the full PCI path?

I am using Ubuntu 19.04.

John Lindgren

Posted 2019-08-10T05:15:52.477

Reputation: 160

Answers

3

Yes, if the tagged device has an associated node in /dev, you can use that directly:

Requires=dev-dri-card0.device
After=dev-dri-card0.device

user1686

Posted 2019-08-10T05:15:52.477

Reputation: 283 655

1This is perfect, thanks. And now I see that the "-a" flag to "systemctl list-units -a -t device" would have shown me this device as well. – John Lindgren – 2019-08-11T15:45:53.180