Systemd trigger for service to wait for external NTFS drive to be mounted?

G’day osmcers,

I have a new Vero (latest updates) and am pretty happy with my 1080p replacement for my aging ATV2.

However I am having some issues with what to trigger my Nzbget and Sonarr systemd services on in order to ensure that the external automount (udisks-glue) drive exists prior to their starting…

## /etc/systemd/system/nzbget.service ##

After=dev-sda1.service  # <----- What should this be to ensure the drive is mounted prior to service start?

ExecStart=/opt/nzbget/nzbget -c /etc/nzbget.conf -D
ExecStop=/opt/nzbget/nzbget -Q
ExecReload=/opt/nzbget/nzbget -O


Any ideas?

Thanks for the help,

Lachlan Pitts (parameme)

There has been quite a bit of discussion about this over a number of threads in the last month or two. (I’m too lazy to try to find the exact threads)

The short answer is that there isn’t anything that you can trigger on, using an ‘After’ clause in the systemd unit, the reason being that an automounter like udisks-glue by definition does not know whether there is a drive to wait for or not until it appears. (hotplug event)

The system doesn’t know that there is a disk there until the hotplug event occurs, up until that point it has no idea whether a drive might or might not appear within a few seconds and whether it should be waiting for one or not. Once the hotplug event occurs the drive will be mounted almost immediately.

So unfortunately there are only really two solutions:

  1. Mount the drive manually in fstab to a different location such as /mnt - now there is an fstab entry systemd knows that a drive is expected to appear at this location and you could wait on this using After

  2. Just add a several second delay to the launch of the service. You could do that with an ExecStartPre:

    ExecStartPre=/bin/sleep 10

Not sexy, but it does work…