There is a systemd unit:

[Unit] Description=home storage folder After=remote-fs-pre.target After=network.target After=network-online.target Wants=network-online.target BindsTo=network-online.target Conflicts=umount.target Before=umount.target [Mount] What=//172.16.100.1/storage Where=/home/username/Shared/storage Type=cifs Options=noauto,x-systemd.automount,noexec,noperm,iocharset=utf8,uid=1000,gid=1000,credentials=/etc/share_creds/home_samba [Install] WantedBy=remote-fs.target 

Mounted Great. It is systemctl stop via systemctl stop without any monstaries.
But if you turn off or restart the computer with the mounted mount, it hangs for a minute and a half while trying to unmount it.
Please tell me which way to pick to get rid of hangs when turning off.

UPD
A couple of clarifications:
1. Kubuntu 18.04.1
2. Naturally NetworkManager taxis

UUPD
With gratitude, I will make decisions on how to catch the moment before breaking the WiFi connection, in order to cram the unmount command in front of it.

So far it turns out only this way:

 #!/bin/bash while read -r line; do [[ "$line" =~ deactivating ]] && { /bin/systemctl stop home-username-Shared-storage.mount } done < <(LANG=en_US nmcli monitor) 

BUT. Yet again. When testing works. Ie, if I manually run this script, I mount the ball by running systemctl start home-username-Shared-storage.mount then when I turn off the WiFi ball, it will be unmounted in a great way. But if you send the car to reboot, again hang for a minute and a half with an attempt to unmount the ball.

UUUPD In the form of a crutch, so far I have thought up to add [Mount] TimeoutSec=5 to [Mount] TimeoutSec=5 In this case, unmounting after 5 seconds simply ends with an error and the computer goes on quietly to rebuild. But if there is a way more beautiful than just strangling the umount process, I will be grateful for the hint.

  • and the logs looked in what order there actually turns off and who exactly hangs? - Fat-Zer
  • Installation is hanging. It writes about it. In the logs, too, only about unmounting. It seems that when rebooting or turning off the NM, it just kills itself (although what an impression, in its unit, the KillMode=process written on the monitor on the monitor) and does not bother about it. I tried to catch the event from nmcli monitor but there is also silent when rebooting - Andrey
  • * on unmounting (the wrap is still ...) - Andrey
  • I would look at the order of actions in the logs: if the problem is because NM is nailed before unmounting, then the problem is most likely in the unit, if not, then maybe it is deeper ... - Fat-Zer

1 answer 1

In general, as they say smart people "smoke mana." Mana rule !!!
Initially, the task was to gain access to the folders on the home server and get rid of hangs in case of an unexpected connection failure.

There were the following introductory:

1) Small home server.
2) It has files that are needed and edited from a home computer, then from a laptop, and not always by me, but I want versions to always be up-to-date.
3) There is also a VPN server based on OpenVPN (respectively, an external IP for connection available)
4) There is a Laptop with Kubuntu 04/18/1 LTS and, accordingly, a NetworkManager taxiste on it, of course, if I am not at home then connect to the server via VPN
5) Often, somewhere outside the house, I connect via phone.

So here. If at the moment when I climbed into the folder and doing something there, or simply forgot to close it, someone will call me, then the file manager hangs tight, so it’s hard to restart.

Already in the process of studying the issue, I found many links to autofs but I wanted not to give up the idea of ​​implementing all this through the searchable (already now) systemd

If someone comes in handy, I'll be glad. I also gladly accept constructive criticism and practical advice from knowledgeable people regarding the implementation of this task.

Own what happened:

mkdir -p ~/Shared/storage
sudo vi /lib/systemd/system/home-<username>-Shared-storage.automount

 [Unit] Description=automounts home storage share Requires=NetworkManager.service home-connection-monitor.service [Automount] Where=/home/<username>/Shared/storage TimeoutIdleSec=301 [Install] WantedBy=remote-fs.target 

sudo vi /lib/systemd/system/home-<username>-Shared-storage.mount

 [Unit] Description=home storage folder Requires=NetworkManager.service home-connection-monitor.service After=home-connection-monitor.service [Mount] What=//<local-share-ip>/storage Where=/home/<username>/Shared/storage Type=cifs Options=nofail,_netdev,noauto,iocharset=utf8,uid=<user_uid>,gid=<user_gid>,credentials=</path/to/file/with/credentials> ForceUnmount=yes LazyUnmount=yes TimeoutSec=5 


sudo vi /lib/systemd/system/home-connection-monitor.service

 [Unit] Description=home connection monitor After=home-<username>-Shared-storage.automount Requires=NetworkManager.service home-<username>-Shared-storage.automount [Service] Type=simple ExecStart=/usr/local/bin/home-connection-monitor Restart=on-failure [Install] WantedBy=remote-fs.target 


sudo vi /usr/local/bin/home-connection-monitor

 #!/bin/bash host='<local-share-ip>' vpn_connection_name='<yor-vpn-connection-name>' test_internet_host='208.67.222.222' # к примеру, можно любой доступный только через интернет. connect_to_home() { printf '%s\n' "$(date +"%d_%m_%Y %H:%M:%S") Trying connecting to ${host}" # Задел на будущее для создания лог файла until ping -W2 -c1 "${test_internet_host}" &>/dev/null; do ping -W1 -c1 "${host}" &>/dev/null && break sleep 1 done ping -W1 -c1 "${host}" &>/dev/null && { printf "$(date +"%d_%m_%Y %H:%M:%S") Connection for ${host} [ \\e[32m%s\\e[m ]\\n" 'established' return 0 } until ping -W1 -c1 "${host}" &>/dev/null; do if nmcli con up "${vpn_connection_name}"; then if ping -W1 -c1 "${host}" &>/dev/null; then printf "$(date +"%d_%m_%Y %H:%M:%S") Connection for ${host} [ \\e[32m%s\\e[m ]\\n" 'established' return 0 fi else sleep 2 fi done } connect_to_home && { while ping -W1 -c1 "${host}" &>/dev/null; do sleep 1 done exit 1 } 

IMPORTANT!!! all between <and> replace your data
IMPORTANT!!! The .mount and .automount files have the names of the corresponding mount point paths, that is, if the mount point path is /media/samba then these files should be called media-samba.mount and media-samba.automount

sudo systemctl daemon-reload
sudo systemctl enable home-karpovan-Shared-storage.{,auto}mount
sudo systemctl enable home-connection-monitor