[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: systemd automount unit: run only when server is reachable



On Mon, 12 Sep 2022 09:31:07 +0200
Jürgen Bausa <Juergen.Bausa@web.de> wrote:

> Using Linux now for a long time I am still not really familiar with
> systemd and have a question on its usage. I am sure this is not the
> best place to ask it (I know, its off-topic), But posting to other
> lists I didnt get an answer. So if you know a better place to ask it
> please point me there.
> 
> I am using systemd automount units (see below) to mount network
> shares on my laptop (debian bullseye). This works fine in principle
> but I have one big issue:
> 
> At home it is enough to set TimeoutSec to 2 s in the mount unit.
> Normally the server is available and the share is mounted. If the
> server is down I need to wait for just 2 s until I see it is not
> there. Thats ok.
> 
> But when not at home and using a vpn, the mount unit will not mount
> with TimeoutSec set to 2 s. I need to set it to at least 10 s. Then
> the mount works. But using 10 s means I always have to wait 10 s for
> each share the system tries to reach and is not available. This is
> really annoying when starting libreoffice for example (which seems to
> check for the last used documents on startup).
> 
> What I would like to do is to put a test for server availabilty (e.g.
> ping -c 1 $SERVER) into the automount file. When the server is not
> available, automount is not run. Is this possible? Or do I need to
> create a spcial unit and put something like
> 
>     Requires=nfs-server-online.target
> 
> in my automount unit? And how would the nfs-server-online unit look
> like?
> 
> What I am doing at the moment is running a script that checks
> availability of the nfs server every some seconds (via ping) and
> turns on/off the automount unit accordingly (via systemctl start/stop
> mnt-share.automount). This works, but its not a very elegant
> solution. I am pretty sure it can be done better using systemd only.
> 
>

I have a number of shares (samba rather than nfs) listed in /etc/fstab 
with the noauto and x-systemd.automount options, among others. Without
the noauto it will assume every fstab entry is required for booting and
will hang on boot if it can't find one. With both, it automounts at
first access, and therefore may never mount if it's not needed for
anything.

I would assume it would work similarly with nfs instead of cifs.

-- 
Joe


Reply to: