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
KillMode=processwritten on the monitor on the monitor) and does not bother about it. I tried to catch the event fromnmcli monitorbut there is also silent when rebooting - Andrey