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

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



systemd has a number of Condition* rules which can be added to units: https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Conditions%20and%20Asserts You could maybe rig something up with that.

Alternatively, if the mount always takes at least 10 seconds, then that sounds like it might be a DNS issue. I see that you're trying to mount the host as "lana". If you're connecting over a VPN, it's likely that you're not using the same DNS resolver as at home, so perhaps something is timing out before it finally resolves. Do you get the same 10 second delay if you mount the path at the command line? If you add "-v" to the mount command, you might see the NFS client trying various options.

On 12/09/2022 08:31, Jürgen Bausa 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.

Regards,

Jürgen

/etc/systemd/system/mnt-share.automount:
[Unit]
Description=autoount share

[Automount]
Where=/mnt/share
TimeoutIdleSec=1min

[Install]
WantedBy=multi-user.target




/etc/systemd/system/mnt-share.mount:
[Unit]
Description=Mount share

[Mount]
Where=/mnt/share
What=lana:/share
Type=nfs
Options=soft,async
TimeoutSec=10

[Install]
WantedBy=multi-user.target


Attachment: OpenPGP_signature
Description: OpenPGP digital signature


Reply to: