1

I'm still struggling to understand boot sequence dependency configuration in systemd unit files. I've read the manual (systemd.unit).

I tried to add dependencies using the After= and Requires= lines to my unit configuration file. However it still regulary fails during system startup because systemd starts it too early before a needed resource (in my case a LUKS encrypted volume) has become available. In my tests it looked like systemd is ignoring these configuration lines. The content of these lines is also not listed when using the command:

systemctl list-dependencies

to check for configured dependencies. Example: My device volume is /dev/dm-6. How can I specify that systemd should wait with starting my unit until this device has finally appeared?

If I start my unit manually in a terminal window after boot using this command:

systemctl start name_of_my_unit

it works fine.

pefu
  • 679
  • 1
  • 6
  • 24

4 Answers4

1

systemd.device might be what you want

A unit configuration file whose name ends in ".device" encodes information about a device unit as exposed in the sysfs/udev(7) device tree. This may be used to define dependencies between devices and other units. ... Device units are named after the /sys/ and /dev/ paths they control. Example: the device /dev/sda5 is exposed in systemd as dev-sda5.device

Links

Andrew Lowther
  • 291
  • 1
  • 4
0

RequiresMountsFor=/mnt/volume

Where the path is in the required mount point.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34
  • I can't use RequiresMountFor= because in my case the problem is the device, which is only mounted later on within the unit. More specific: The LUKS device and the cryptsetup is handled in a Xen dom0 domain and the systemd unit in question is starting a virtual machine to which this device has to be attached to before starting. – pefu Jan 05 '22 at 08:04
0

May be you should check ExecStartPre= and ExecCondition=. Looks like they able to solve your issue.

Alexander Tolkachev
  • 4,608
  • 3
  • 14
  • 23
0

I am also facing something similar where the service is getting started before the Luks device under /dev/mapper is getting created.

When I do "systemctl start myservice" it works fine.