0

So, I have created a systemd mount unit to mount my NAS and that works great. However, I don't want to have to start and stop that service myself when I know the NAS is on and available. I was hoping I could use PathExists to check to see if my computer could see the network drive over at <ip>:/mnt/dir but this doesn't seem to work.

Is there a way to have systemd check if a network drive is available (and then subsequently run start the mount unit) without me being involved?

4
  • is there any reason to not use systemd.automount?
    – arana
    Commented Apr 16, 2019 at 22:01
  • If I understand it will just attempt to mount a filesystem that may not actually be there and then fail?
    – RhythmInk
    Commented Apr 16, 2019 at 22:06
  • nevermind, I totally ignored the fact that it is a NAS drive and not physically connected to your system. You could try to do it with autofs, it will mount it whenever you want to access it. here is the ubuntu help page help.ubuntu.com/community/Autofs
    – arana
    Commented Apr 16, 2019 at 22:30
  • Because that would still attempt to mount a filesystem that may not be available.
    – RhythmInk
    Commented Apr 16, 2019 at 23:23

1 Answer 1

1

PathExists= deals with locally visible paths. If it is not already mounted on the local system, then it does not exist.

The problem is that there isn't a single "default" protocol for connecting to a "network drive" – it might be NFSv3 or NFSv4, it might be SMBv1 or SMBv3, it might even be FTP or FTPS or SFTP or AFS or WebDAV – and neither the kernel nor systemd make an attempt to 'transparently' support any of them.

Use a background task (e.g. a cronjob or a .timer) that periodically checks whether the NAS is available using its own methods and starts/stops the .mount accordingly.

You must log in to answer this question.

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