i have 2 local dirs on my server mounted on a remote server. Local maintains connections with autossh -M 23 -R 24:localhost:22 user@server While remote mounts with dirs-sshfs.sh

sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,cache_timeout=3600 user@ /home/user/dir1/ -p 24
sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,cache_timeout=3600 user@ /home/user/dir2/ -p 24

When it locks up, sshfs-restart.sh is used to reset the connection

pkill -kill -f "sshfs"
fusermount -uz dir1
fusermount -uz dir2

That all works fine, but i have to 1) notice that it locked up and 2) manually reset it.

What makes this tricky is that when it locks up, even ls of home dir is infinitely locked up until reset. Because of this, i have given up on this being managed from the remote server side. On my local server side, where the autossh connection is maintained, i have this following script that almost works. This does catch when it fails, and tries to reset the connection, but will not remount after unmounting. Tried putting dirs-sshfs.sh content inside ssh-restart.sh, and even run-sshfs-restart.sh remote server side which contained ./sshfs-restart.sh & did not get it to work. The test script (testsshfs2.sh) contains ls; echo; ls dir1; echo; ls dir2; echo; date; echo which was created to be a quick and easy way to check if everything is mounted/working.

This is sshfsmanager.sh, run from local server inside a while loop with a sleep command. Future will probably move it to a cronjob

sshout=$(timeout 300 ssh user@host ./testsshfs2.sh)
# timeout duration probably doesnt need to be that long, but sometimes it does take 90+ sec to ls
# the remote dirs as they are network shares mounted to a vm that are then mounted across a ssh
# tunnel. Once this is working, that duration would be fine tuned. Also 100 is just an arbitrary
# number larger than ls | wc -l would provide. It should be updated to where it would catch if
# either of the mounts fail instead of only when both do. This timeout method is the only way
# ive found to get around the infinite ls lock.

if [ `echo "$sshout" | wc -l` -le 100 ]; then
  echo "$sshout" | wc -l
  ssh user@host ./sshfs-restart.sh
  #adding a "&& sleep 60" or using the run-sshfs-restart.sh script did not work

  echo sshfs restarted
  echo sshfs is fine
  echo "$sshout" | wc -l

Most the scripts have logging that was removed when put here (as well as changing ports and removing user/host). Most all the logging lines are just date >> sshfsmanager.log

Local VM is running ubuntu 18.04.5 and remote server is a shared VPS running gentoo 5.10.27

  • Try "systemctl status sshfs" and"systemctl restart sshfs". Also, if the status is anything but "actiave", then you should use the journal and log files to investiage why. The problem may have nothing to do with sshfs - it may be just a causality. How is TCPKeepAive set in sshd? Jun 15 at 0:58
  • @CinaedSimson systemctl and systemd command not found. I updated the question to include the os at the bottom. Local VM has TCPKeepAlive line commented out. About a year ago the provider aid the slot freezing, and software that tried to use the mounted locations freezing too, was due to sshfs mount crashing. I know is if i ssh into vps and run sshfs-restart.sh, the problem is fixed, but if it is a symptom i would rather fix the root issue. Jun 15 at 3:00
  • I do not have root access on vps. The main issue here is that ssh user@host ./sshfs-restart.sh does not remount from within the script but ./sshfs-restart.sh does work by hand over ssh. Jun 15 at 3:44
  • Okay, I would guess the connection is timing out. Have you tried adding "ServerAliveInterval 5" (no quotes) to your ~/.ssh/config file? It should wake up the server every 5 seconds. Jun 15 at 4:13
  • Added remote server side, and ran sshfs-restart.sh so it will be a new connection. Local side, since autossh maintains the connection, i did not add it. If this works then wont even need a monitoring script. Sometimes it crashes multiple times in a day, and sometimes will go a week or 2 before having an issue. If it crashes again ill update, or if a month without a problem will assume fixed and mark question as so. Jun 15 at 4:52

Your Answer

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

Browse other questions tagged or ask your own question.