1

I set up a CIFS share on my ubuntu

Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04

using an fstab entry:

//mystr.myserver.com/backup /mnt/mystr       cifs    iocharset=utf8,rw,_netdev,credentials=/etc/smb/mystr-credentials,uid=someuser,gid=0,file_mode=0660,dir_mode=0770 0       0

which works as expected.

now i do have smbd running to provide this share to users on my LAN with this section in /etc/samba/smb.conf

[mystr]
path = /mnt/mystr
public = yes
writeable = yes
browsable = yes
guest ok = yes
force user = someuser

which also works fine.

However there seems to be an issue if the IP address of the entry mystr.myserver.com changes. The share says "Host is down." and mount shows me the outdated IP address.

As this does not happen very often it is not easy to reproduce. This morning I wanted to fix it manually and tried to unmount it first which gave me Resource is busy as I think the smbd process is blocking the share.

Stopping the smbd process, unmounting the share, using mount -a and restarting smbd solved the issue.

So my questions are: Can this be done automatically? Can I tell fstab to force re-mounting the share if it is down? Is this even related to smbd having a handle on the directory? I checked lsof, but could not find anything related. Can I tell samba to "let go" of unreachable directories?

Thanks in advance for any ideas/Suggestions.

Flo
  • 146
  • 5

1 Answers1

0

Sadly i could not find a way to do this automatically so i wrote a script and added it to crontab

this is now running once every minute.

#!/bin/bash
for d in $(find /mnt/ -maxdepth 1 -mindepth 1 -type d); do
        if [[ "$d" == *"Host is down"* ]]; then
                $(systemctl stop smbd)
                $(umount -a -t cifs -l)
                $(mount -a)
                $(systemctl start smbd)
        fi
done

I'm using unmount for each CIFS storage and remount them using mount -a once the script detects a offline mount with the message Host is down. Maybe stopping smbd is not necessary but shouldn't cause any issues here.

this might not be ideal, but does the job.

Flo
  • 146
  • 5