I'm trying to find a way to do this. Right now I have a script that will only allow samba to be reset by running "smbstatus", but it isn't very reliable (shows locked files when a Windows client has mapped a share, with no file activity).

Is there any way to detect when Samba has files being transferred?

NOTE: Only active file transfers, not mapped clients

EDIT: Here is what my script looks like

until sudo smbstatus | grep "No locked files"
    echo "Processes Running..."
    sleep 5
    echo ""
sudo service smbd restart
echo "Restarted SMB"

You may want to use the deadtime setting to kill child smbd processes that are not being actively used.

Example, which kills a child process after it has been unused for 10 minutes:

deadtime = 10

The documentation notes, amongst other things, that

The deadtime only takes effect if the number of open files is zero.

Most clients have an auto-reconnect feature when a connection is broken so in most cases this parameter should be transparent to users.

Using this parameter with a timeout of a few minutes is recommended for most systems.

Using this scheme you can count the number of child processes and perform your reset when there is only the parent process remaining. (Mind you, it might be luck but I have not recently had any problem restarting the parent smbd process even while child processes are still running.)

  • Thanks for your reply! Just added my script to the question... when any Windows client maps out a share, "smbstatus" will report there are locked files. I tried using deadtime, but Windows keeps the connection alive somehow by just being connected to it – Tyler33444 May 29 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.