6

I'm writing a systemd's .service file for minidlnad (DLNA server) under CentOS 7. Since my media file collection is hosted on a RAID array, I need that array to be mounted BEFORE the minidlnad server is started. Both the RAID array and minidlnad should be started on boot. Is there a way to do this in systemd?

2 Answers 2

3

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

6
  • Is this enough to be sure that the raid device is also mounted (as specified in /etc/fstab) and not just assembled?
    – Marcello
    Jun 22, 2015 at 12:09
  • edited to be sure that local-fs.target is already activated
    – maxxvw
    Jun 22, 2015 at 12:26
  • Apparently I don't have a mdadm.service file in /usr/lib/systemd/system, just [email protected], [email protected] and [email protected]. Should I still put the mdadm.service entry in requires and after?
    – Marcello
    Jun 22, 2015 at 12:52
  • Sorry don't have a centos installed to try, but it seems that you may have a /usr/lib/systemd/system/mdmonitor.service which is the one you should use, i'll edit my answer
    – maxxvw
    Jun 22, 2015 at 13:07
  • Yes, I have mdmonitor.service and it does execute that command. Thank you very much!
    – Marcello
    Jun 22, 2015 at 13:43
11

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

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

4
  • 1
    I'd disagree with your comment above that "this is not the preferred systemd way". RequiresMountsFor= is ignored if the mount point is marked noauto, so sometimes the explicit Requires target is not only recommended but required.
    – Auspex
    Jul 9, 2016 at 20:53
  • @Auspex The OP clearly stated that the question relates to system boot. In this regard, the title of the Q may be seen as incomplete, while my answer addressed this scenario. Do you see a case where a noauto option would be used during boot?
    – Run CMD
    Jul 12, 2016 at 18:03
  • I don't think it's relevant whether "noauto" would be used during boot. You argued with the accepted answer because you claimed it was not the preferred systemd way. I see nothing in the documentation to say that, and reasons why you might want to avoid your method.
    – Auspex
    Jul 13, 2016 at 10:52
  • 1
    @Auspex I also don't think it's relevant when noauto is used. It's just that the OP's use case suggests that he's not going to use noauto. That's got nothing to do with the documentation, but rather with the scenario of the question.
    – Run CMD
    Jul 20, 2016 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .