Start a systemd service after a device has been mounted

systemd has a specific directive for this case, called RequiredMountsFor; see man systemd.directives.

The usage would be RequiresMountsFor=[mountpoint], e.g. RequiresMountsFor=/var.


You need to adjust dependencies in your .service's Unit section:

On centos:

Requires=mdmonitor.service local-fs.target
After=mdmonitor.service local-fs.target

On other distrib, it could be:

Requires=mdadm.service local-fs.target
After=mdadm.service local-fs.target

The raid service file should execute /sbin/mdadm --monitor --scan

source:http://www.freedesktop.org/software/systemd/man/systemd.unit.html