The correct setup is for unit
nfsshare.mount to contain:
And for unit
nfsshare.automount to contain:
And you typically want to enable the
.automount unit only:
$ sudo systemctl enable nfsshare.automount
With this setup, right after you boot (assuming no running daemons have accessed the NFS share), then the share will not be mounted. But once it is accessed (with e.g.
ls /nfsshare) then it will be mounted on demand. It will stay mounted for 10s and then unmounted, but mounted once again after accessed another time.
The two units
.automount work together to trigger this behavior. The
.automount unit simply needs to know the mount point directory where to set up an automount. Once that directory is accessed, then it will trigger a request for the
.mount unit with the same name (for the same path) and will wait until that unit is up before proceeding.
See the man page for automount units for more details.
What else have I changed from your setup?
For networking dependencies, you should use
.service which doesn't exist. I'm also using
Wants=, which is the recommended directive for this case (see this wiki page for a deeper discussion on the network targets.)
user from your mount options, as those only really make sense in
/etc/fstab. I'd also argue you don't really want to have
user in there, just have it automounted instead of allowing unprivileged users to mount it calling the
mount util, automounting is better.
The directives taken on which unit are distinct (except for
Where= that is taken by both), so I only kept the valid ones there.
I removed the
[Install] section of the
.mount unit, since you don't need to enable it. You only need to enable the
.automount unit so it's brought up at boot, then that unit will be responsible for bringing up (and down) the mount unit whenever needed (depending on the target directory being accessed.)
Note that you can also configure all this (including the automount) in
/etc/fstab. In fact, systemd typically recommends using
/etc/fstab for configuration rather than creating mount units.
For automounting, all you need to do is add a
x-systemd.automount pseudo-option to the list of mount options of your
/etc/fstab entry for this filesystem. (You typically want to include
noauto as well in that case.)
See this section of the Arch Linux wiki for more details. (None of that is really specific to Arch Linux, it should all work exactly the same on RHEL 7.)