Contact us
Leave a message

Please use:

My public cryptographic key


Member of

Home Is Everywhere

By now, we are running a completely Windows-free household, and virtually all our Linux-based family PCs (desktops, laptops, Steam deck...) are managed through ansible in a way ensuring that all family members will find the same environment on every machine. To this end, a user-specific roaming directory, residing on our home server, gets mounted into a dedicated sub-folder inside each user's home directory.

The Challange...

Remote mounting is realized through sshfs. Now the question is: Under which name and on which port should the server be contacted?

  • Using the host name the server is known by in the local network? This surely provides the fastest connection, but won't work when trying to connect e. g. using a laptop while on the road.
  • Using the domain name and port the server is reachable by from the internet? This surely always works, but unconditionally enforces round trips through the sluggish internet connection, even when connected to the local network.

...And The Solution

What if the best connection was automatically chosen, depending on which network the computer is connected to? Well, that's exactly what server-mount.py does!

The script is intended to act as a handler that gets invoked by NetworkManager whenever the system's connection status changes; alternatively, it can be run periodically by systemd. For the former, it should be symlinked e. g. as 99-server-mount.py from within the /etc/NetworkManager/dispatcher.d directory, for the latter, just install the provided server-mount.service file.

Then, on any network status change, the following things will happen:

  • The script iterates through all configured network connections (each characterized by host name, port and path on the server to the directory containing the users' roaming folders) and determine via ping whether the server is reachable under the respective host name.
  • The search terminates at the first successful connection test.
  • All other host names are iterated through; for each host name, all possibly still active remote user mounts get unmounted.
  • If a reachable host was found, the script ensures that there's an active remote mount set up for each user.

Configuration

The scirpt expects a configuration file called server-mount.json at one of the three following locations:

  • current working directory
  • the directory the script resides in
  • /etc

The configuration file is required to have the following structure:

{
	"networks": [
		{
			"host": "host_in_local_network",
			"port": 22,
			"root": "/home"
		},
		{
			"host": "same_host.mydomain.net",
			"port": 2022,
			"root": "/home"
		}
	],
	"mountpoint": "roaming"
}
  • The networks list may have an arbitrary number of entries.
  • As mentiones above: The first working entry wins. Therefore, the fastest connections should appear at top positions within the list.
  • In case of a successful connection, each users' server directory <root>/<username> will be mounted in his/her local <user-home>/<mountpoint> directory.

Nota Bene:

  • The script should run with sufficient privileges for executing (un)mount actions for each user. (Should anyway be the case when called by the NetworkManager.)
  • To allow for password-less authentication, all users' public SSH keys must be added to their corresponding ~/.ssh/authorized_keys on the server.
  • The script's output goes directly into the syslog, not to stdout.

Download

See my Gitlab page.