Start Systemd Service After Device Appears

From JoBaPedia
Jump to navigation Jump to search

What if you install a service on a volume group located on a separate disk that is not necessarily mounted at boot?

  • Create fstab entries with nofail option
/dev/dbvg/db2mspr      /home/db2mspr         xfs       nofail                   0  0
  • Create UDEV rule to activate the vg and mount the fs once the device appears
KERNEL=="devNameHere", RUN+="/bin/bash -c '/sbin/pvscan --cache -a ay && mount -a -O nofail'"
  • Add a require directive for the mount point to the service file
[Unit]
RequiresMountsFor=/home/db2mspr
...