INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Auto-reconnect to media server when it reboots?  (Read 1636 times)

pepar

  • World Citizen
  • ***
  • Posts: 248
Auto-reconnect to media server when it reboots?
« on: March 10, 2020, 02:48:09 pm »

I have an unRAID box with my media files. I have Linux running on a small NUC set up to auto logon at boot along with automounting the unRAID Samba media share and auto-launching MC. Occasionally, I restart the unRAID box and find that Media Center no longer sees the files, i.e. the Samba share is not mounted.

Is there a way to setup the Linux/MC box to re-mount the unRAID SMB share when unRAID comes back up? I can remotely operate unRAID, but I need to go to the basement server closet to reboot Linux/MC.

I have been looking at VNC with the thinking that that would allow me to remotely control the Linux/MC box.

Am on the right path? Remote desktop or is there a way to restore a mounted network share?

Thanks,
Jeff
Logged
"I like the future, I'm in it." F. Theater

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Re: Auto-reconnect to media server when it reboots?
« Reply #1 on: March 11, 2020, 08:25:47 am »

So this can be fiddly, but there are solutions.  The first thing you should do is diagnose what's happening on NUC when the samba share isn't mounted.  If it's cleanly unmounted that's a different case than if it's mounted but hanging because the server went away.  If the share is cleanly unmounting, you can just configure it to mount on demand instead of automounting at boot.  If instead you find that you can't mount the share because the OS thinks it's already mounted and it's not responding, you'll need the fix below.  VNC is a good way to diagnose and manually fix a problem, but ideally you want an automated solution.

My experience is that you can get a "stuck" condition if a samba share goes away when a client system has it mounted.  When that happens you need to "umount -l" the share and then remount them manually, which is not ideal.  A reboot would work too, but that's even less ideal.  The solution I use is to mount the share automatically on demand and (crucially) to unmount it when it's not in use, so if the server goes away the client mostly doesn't notice.  There still may be mount issues if the server goes away when the client is actively using it, but that's a harder nut to crack. 

My (partial) solution in the form of a pseudo /etc/fstab entry is below (you'll need to replace all the placeholders with your own info, obviously):

Code: [Select]
//samba.server.ip.address/sharename /local/mountpoint cifs noauto,x-systemd.automount,x-systemd.idle-timeout=5min,_netdev,your_other_mount_options_here 0 0
So the magic is in the middle.  The noauto option avoids trying to mount the share at boot (which you want, as it might slow the boot otherwise), and then the x-systemd.automount option automagically mounts the share whenever any program tries to access the mount point.  This will work to automount the share on an as needed basis.  Crucially the x-systemd.idle-timeout option unmounts the share when no program has accessed it for five minutes, but the automount flag will just reconnect automatically the next time a program needs it.  This ensures that, most of the time, if the host goes away the client isn't actively mounted so the next automount is "clean."  The _netdev flag makes it clear to the OS that the mount is a network device instead of a local one which can help with some issues if a program tries to access the share before the network is up.

Hope this helps!

Logged

pepar

  • World Citizen
  • ***
  • Posts: 248
Re: Auto-reconnect to media server when it reboots?
« Reply #2 on: March 11, 2020, 11:37:28 am »

Thank you for the thorough explanation! Since this is the MediaCenter forum, I would guess that your context is for when MC would try to access the media content? So, MC's library has paths to the content titles and simply "peeking" (dates me, doesn't it?) at that path automounts the share? What about the periodic scanning for new content to import ... that also causes the share to automatically mount? Do these mounts happen fast enough for MC to not time out?

Jeff
Logged
"I like the future, I'm in it." F. Theater

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5174
  • "Linux Merit Badge" Recipient
Re: Auto-reconnect to media server when it reboots?
« Reply #3 on: March 11, 2020, 11:45:14 am »

Thank you for the thorough explanation! Since this is the MediaCenter forum, I would guess that your context is for when MC would try to access the media content? So, MC's library has paths to the content titles and simply "peeking" (dates me, doesn't it?) at that path automounts the share?

Any attempt to access the share will mount it, so if MC interacts with or scans the directory it will mount.

Quote
What about the periodic scanning for new content to import

I'm less sure about this.  It clearly would prevent realtime notifications (i.e. it won't sense new files added from elsewhere if the mount isn't mounted), but I don't think it interferes with the periodic scans.  If you're adding the files on the same computer autoimport should work as well as it ever does on cifs because the mount is mounted. It hasn't come up in my use because my MC server is where the files are so isn't relying on samba to see new files.

Quote
Do these mounts happen fast enough for MC to not time out?

In my experience, yes, it happens very quickly somewhere between a quarter second and a second of lag on first mount for me.  Try it and see how it works on your network.

As I noted above, you may be able to get by without the idle dismounting, it just depends on whether the shares unmount gracefully on your client when the samba server goes away.
Logged

pepar

  • World Citizen
  • ***
  • Posts: 248
Re: Auto-reconnect to media server when it reboots?
« Reply #4 on: March 11, 2020, 12:32:43 pm »

I'm less sure about this.  It clearly would prevent realtime notifications (i.e. it won't sense new files added from elsewhere if the mount isn't mounted), but I don't think it interferes with the periodic scans.  If you're adding the files on the same computer autoimport should work as well as it ever does on cifs because the mount is mounted. It hasn't come up in my use because my MC server is where the files are so isn't relying on samba to see new files.
I'm not sure if unRAID is generating file system events of if they would be passed along with a share, but the periodic scan is apparently working.

Quote
In my experience, yes, it happens very quickly somewhere between a quarter second and a second of lag on first mount for me.  Try it and see how it works on your network.
I will do that!

Quote
As I noted above, you may be able to get by without the idle dismounting, it just depends on whether the shares unmount gracefully on your client when the samba server goes away.
I don't know either so I will use the unmount step.

Thanks again!

Jeff
Logged
"I like the future, I'm in it." F. Theater

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3959
Re: Auto-reconnect to media server when it reboots?
« Reply #5 on: March 11, 2020, 04:09:16 pm »

Don't think SMB/cifs supports inotify so a sensible implementation will fall back to polling anyway
Logged
Pages: [1]   Go Up