systemd seems to stop network before unmounting network drives

Hello!

I have a laptop that runs Leap 15, with an OpenVPN connection that is started at boot time by systemd’s openvpn@.service. The device uses NetworkManager; once the user logs in and WiFi is connected, then OpenVPN finds its server and connects.

I have the following in /etc/fstab:

10.62.0.1:/srv/shared   /mnt/shared   nfs4   _netdev,noauto,user,exec   0   0

The 10.x.y.z subnet refers to the VPN. Yes, I know – DNS good, IPv6 good, hardcoded 10.x.y.z addresses bad. We’re working on it. :^)

The mount is “noauto” because a network connection may not be available at boot time (remember NetworkManager, wifi). It is also a “user” mount because the user needs to be able to remount the device without superuser privileges, e.g. if the network connection was lost and is restored. (The OpenVPN process keeps running even if the network goes down, and will reconnect automatically when the network is back.)

The problem with this setup occurs when shutting down. If the user remembers to unmount the shared folder, shutdown is clean and fast. If the user initiates shutdown while the shared folder is mounted, it appears that the network connection (and/or OpenVPN?) go down before the folder is unmounted. It is then not possible to cleanly unmount the folder. The device hangs for five minutes, until the folder is eventually hard-unmounted by timeout.

I am guessing there is something I need to add or change in the systemd module files (like adding a WantedBy=x or After=x line somewhere), but I could use some help here!

This is almost a “vanilla” Leap 15 install, by the way, and there haven’t been any manual changes to the systemd configuration. Could this count as a bug?

By the way: yes, I am aware that the user may fusemount an NFS4 share instead. The reason why we’re not doing that is because the /etc/fstab approach gives us root-level control of the mount point. This path is then used by other processes, e.g. a daily data back-up to the network drive.

Best,
/K.

If network is started as part of your login session, it also stops as part of your login session. Which is intentionally happens before anything is unmounted (on assumption that user session may need access to mounted resources).

I am guessing there is something I need to add or change in the systemd module files (like adding a WantedBy=x or After=x line somewhere), but I could use some help here!

I do not think it is possible to express using systemd dependencies. There is no point in time “after all user sessions”.

If you configure network and mount as part of user session, you should really unmount as part of user session too.

Been awhile since I’ve looked at shutdown related dependencies, but generally it starts with the method used for shuttting down… What actually happens depends on the Desktop being used, then inspecting the hooks that can be written to that method.

Otherwise,
If for example you want to sue the systemd shutdown and poweroff commancds, you can put a shortcut on the Desktop and then modify that Unit file.

TSU

You are using NetworkManager. So you could put a script in “/etc/NetworkManager/dispatcher.d/pre-down.d/”. In that script you just check whether the folder is still mounted and if so unmount it.

See

> man NetworkManager

for more details.

Regards

susejunky