You are not logged in.
Hi there,
I'm currently tweaking my nfs setup.
What do I want
Mount my exported directories via bind to export, when the nfs-server starts. And unmount the directories on stop of the nfs-server
Approach
/etc/systemd/system/nfs.target
[Unit]
Description=Network File System Server
Wants=export-daten.mount export-daten-Downloads.mount export-portage.mount export-root.mount export-root-boot.mount
Requires=nfs-server.service
BindsTo=nfs-server.service
[Install]
WantedBy=multi-user.target
/etc/systemd/system/export-daten.mount
[Unit]
Description=/home/blubb/Daten nach /export/daten
BindsTo=nfs-server.service
StopWhenUnneeded=true
[Mount]
What=/home/blubb/Daten
Where=/export/daten
Options=bind
[Install]
WantedBy=nfs.target
ls nfs.target.wants
export-daten-Downloads.mount export-daten.mount export-portage.mount export-root-boot.mount export-root.mount
nfs-server.service is the original one shipped by Arch in /usr/lib/systemd/system.
Current behaviour
start nfs.target: mounts directories, starts nfs-server
stop nfs.target: unmounts directories, doesn't stop nfs-server
start nfs-server.service fails, because can't export /export/daten/Downloads, which doesn't exist, because the mount-units were not processed.
stop nfs-server.service: umount directories (due to the BindsTo directive) and stops the nfs.target.
Desired behaviour
The current behaviour works, but isn't very clean. Would be nice, if nfs.target stops the nfs-server.service too. I don't want nfs-server.service copy to /etc and modify as I will miss any updates of the original unit in /usr/lib.
Is it possible to stop nfs-server.service in/by nfs.target?
Offline
I don't want nfs-server.service copy to /etc and modify as I will miss any updates of the original unit in /usr/lib.
You can add something to a unit file without doing this, as is explained in 'man systemd.unit':
Along with a unit file foo.service, a directory foo.service.d/ may exist. All files with the suffix ".conf" from this
directory will be parsed after the file itself is parsed. This is useful to alter or add configuration settings to a unit,
without having to modify their unit files.
So you can create a 'nfs-server.service.d/custom.conf' file with:
[Unit]
BindsTo=nfs.target
Normally this should stop the nfs-server service when nfs.target is stopped.
It needs testing to confirm it though.
Offline
Tanks, works so far. One problem is left.
For some reason, nfs option nohide doesn't work. So I have to export other filesystems in subtree too. My 2 units:
export-daten.mount
[Unit]
Description=/home/sm/Daten nach /export/daten
BindsTo=nfs-server.service
StopWhenUnneeded=true
[Mount]
What=/home/sm/Daten
Where=/export/daten
Options=bind
[Install]
WantedBy=nfs.target
and the filesystem, which is mounted in there:
export-daten-Downloads.mount
[Unit]
Description=/home/sm/Daten/Downloads nach /export/daten/Downloads
BindsTo=nfs-server.service
Requires=export-daten.mount
StopWhenUnneeded=true
[Mount]
What=/home/sm/Daten/Downloads
Where=/export/daten/Downloads
Options=bind
[Install]
WantedBy=nfs.target
According to the Manpage I'm not sure, if the Requires option is even recognized. Mounting works. But when I stop my nfs-server, I get this message:
journalctl
Feb 12 07:23:53 Nas systemd[1]: Stopping Network File System Server.
Feb 12 07:23:53 Nas systemd[1]: Stopped target Network File System Server.
Feb 12 07:23:53 Nas systemd[1]: Unit export-daten-Downloads.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Unit export-portage.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Unit export-root-boot.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Unmounting /boot nach /export/root/boot...
Feb 12 07:23:53 Nas systemd[1]: Unit export-root.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Unmounting /var/portage nach /export/portage...
Feb 12 07:23:53 Nas systemd[1]: Stopping NFS server and services...
----------------------------------------
Feb 12 07:23:53 Nas systemd[1]: Unmounting /home/sm/Daten/Downloads nach /export/daten/Downloads...
Feb 12 07:23:53 Nas systemd[1]: Unit export-daten.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Unit export-root-home-sm-Daten-Downloads.mount entered failed state.
----------------------------------------
Feb 12 07:23:53 Nas kernel: nfsd: last server has exited, flushing export cache
Feb 12 07:23:53 Nas systemd[1]: Unmounted /boot nach /export/root/boot.
Feb 12 07:23:53 Nas systemd[1]: Unit export-root.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Unmounted /var/portage nach /export/portage.
Feb 12 07:23:53 Nas systemd[1]: Unmounted /home/sm/Daten/Downloads nach /export/daten/Downloads.
Feb 12 07:23:53 Nas systemd[1]: Unit export-daten.mount is not needed anymore. Stopping.
Feb 12 07:23:53 Nas systemd[1]: Stopped NFS server and services.
Feb 12 07:23:53 Nas systemd[1]: Stopping NFS Mount Daemon...
Feb 12 07:23:53 Nas rpc.mountd[21709]: Caught signal 15, un-registering and exiting.
Feb 12 07:23:53 Nas systemd[1]: Unmounting /home/sm/Daten nach /export/daten...
Feb 12 07:23:53 Nas systemd[1]: Unmounting / nach /export/root...
Feb 12 07:23:53 Nas systemd[1]: Stopped NFS Mount Daemon.
Feb 12 07:23:53 Nas systemd[1]: Unmounted /home/sm/Daten nach /export/daten.
Feb 12 07:23:53 Nas systemd[1]: Unmounted / nach /export/root.
Manpage:
If a mount point is beneath another mount point in the file system hierarchy, a dependency between both units is created automatically.
It seems, that works for mounting, but not for the umount.
Can I do something to unmount that stuff cleaner?
Offline
Sorry but I don't understand 'nach' in the journalctl output.
Can you explain more clearly the problem with the umount.
Because I see:
Feb 12 07:23:53 Nas systemd[1]: Unmounted /home/sm/Daten/Downloads nach /export/daten/Downloads.
...
Feb 12 07:23:53 Nas systemd[1]: Unmounted /home/sm/Daten nach /export/daten.
So what is the problem?
Offline
Sorry for the language stuff. "nach" means in this case "to".
You're right, the sequence is correct. But why do I get this message:
Unit export-root-home-sm-Daten-Downloads.mount entered failed state.
Offline