Auto mount network shares: autofs
Edited to make it work correctly
- It wasn’t surviving reboots
- I had given my mac a permanent IP for another reason so I decided to use that
- I renamed the Calibre Library share to Calibre-Library in order to get rid of the pesky space/em>
- I was also attempting to get Calibre-Web to run from a LaunchDaemon
Apparently there is a BSD utility called autofs
that mounts network drives on demand. And with OS X’s unix underpinnings this means it works on your Mac.
This is revolutionary. If you’ve worked in a server environment or tried to store your iTunes or iPhoto library on an external drive you will know, things like network outages, reboots or even taking your laptop offsite will mean you have to reconnect, which while not arduous, is a bit annoying and often hard to explain to users.
In my case I run Calibre-Web on my mac-mini server but house the calibre db on my personal machine. Which means I resorted to writing a script to reconnect every time I rebooted something…which seemed to be be pretty often.
The code
Disclaimer: this is the code for my old mac mini which is stuck on High Sierra 10.13.6. I have read (see links below) that it works slightly differently for newer versions of OS X.
First off edit the auto_master file to insert the auto_smb line and comment out the /net line:
sudo nano /etc/auto_master
#
# Automounter master map
#
/mount auto_smb
+auto_master # Use directory service
#/net -hosts -nobrowse,hidefromfinder,nosuid
/home auto_home -nobrowse,hidefromfinder
/Network/Servers -fstab
/- -static
Then you will create the config file you specified above (auto_smb):
sudo nano /etc/auto_smb
The first bit is the location of the share. In this case I called it calibre and wanted it to mount in the volumes folder with all the the rest of the regular mounts.
Then you need to add the login information including your name and password and the network location. An IP will work just as well if you are using a static one.
Calibre-Library -fstype=smbfs,rw ://username:password@192.168.1.20/Calibre-Library
Other Uses
At some point I am going to move L’s ever-growing music library to something like a NAS (network attached storage) and this will be a godsend if it works the way it has so far. Fingers crossed.
Sources
https://useyourloaf.com/blog/using-the-mac-os-x-automounter/
Afterword
After all that, it doesn’t solve the problem I thought it would. When my mac hosting the calibre library goes down it send the python code in Calibre-Web into an unrecoverable tailspin. So even though the share comes back up it still needs a restart to make it happy again. So I am only halfway there.