On Wed, 2025-12-10 at 11:50 -0500, Steven A. Falco wrote:
> I posed the question to ChatGPT, and settled on making the NFS mounts
> be "noauto", and then creating a service to wait for the network to
> truly be up before mounting the filesystem.  This works well for me,
> and I've attached the service file in case it benefits anyone else.

And ChatGPT produced something that sort-of works, but it is
unnecessarily complicated...

> [Unit]
> Description=Mount all NFS client filesystems once NAS is reachable
> After=network-online.target NetworkManager-wait-online.service
> Wants=network-online.target NetworkManager-wait-online.service
> 
> [Service]
> Type=oneshot
> 
> # Wait until the NAS actually responds to ping (up to ~30s)
> ExecStartPre=/usr/bin/bash -c 'for i in {1..30}; do ping -c1 -W1 nas
> >/dev/null 2>&1 && exit 0; sleep 1; done; exit 1'
> 
> # Now mount each share explicitly; "noauto" does NOT block these
> ExecStart=/usr/bin/mount /shared
> 
> RemainAfterExit=yes
> 
> [Install]
> WantedBy=multi-user.target

Let's consider the following service instead:

[Unit]
Description=Wait till NAS is reachable
After=network.target
Before=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=sh -c 'while ! ping -c1 -W1 nas >/dev/null 2>&1; do sleep 1;
done'

[Install]
WantedBy=multi-user.target

+ it doesn't require any changes to fstab
+ it doesn't hardcode timeout, relying on the systemd-provided one
instead
+ it doesn't have superfluous dependencies
- it delays start of everything that is ordered after network-
online.target , not just the mount of a single network disk, but that's
probably not a big deal

D.

-- 
_______________________________________________
devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to