當 sshfs 鎖定時自動重置,重新掛載失敗,除非手動完成

當 sshfs 鎖定時自動重置,重新掛載失敗,除非手動完成

我的伺服器上有 2 個本機目錄安裝在遠端伺服器上。本地與 dirs-sshfs.sh 保持連接, autossh -M 23 -R 24:localhost:22 user@server而遠端掛載

sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,cache_timeout=3600 [email protected]:/mnt/localdir1/ /home/user/dir1/ -p 24
sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,cache_timeout=3600 [email protected]:/mnt/localdir2/ /home/user/dir2/ -p 24

當鎖死時,使用sshfs-restart.sh重置連接

pkill -kill -f "sshfs"
fusermount -uz dir1
fusermount -uz dir2
./dirs-sshfs.sh

一切正常,但我必須 1)注意到它已鎖定並 2)手動重置它。

棘手的是,當它鎖定時,即使主目錄的 ls 也會無限鎖定,直到重置。因此,我放棄了從遠端伺服器端進行管理。在我的本機伺服器端,維護 autossh 連線的地方,我有以下幾乎可以工作的腳本。這會在失敗時捕獲,並嘗試重置連接,但在卸載後不會重新安裝。嘗試將 dirs-sshfs.sh 內容放入 ssh-restart.sh 中,甚至 run-sshfs-restart.sh 包含的遠端伺服器端./sshfs-restart.sh &也無法使其運作。測試腳本(testsshfs2.sh)包含ls; echo; ls dir1; echo; ls dir2; echo; date; echo它,它的創建是為了一種快速、簡單的方法來檢查所有內容是否已安裝/工作。

這是 sshfsmanager.sh,使用 sleep 指令在 while 迴圈內從本機伺服器執行。未來可能會將其轉移到 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
else
  echo sshfs is fine
  echo "$sshout" | wc -l
fi

大多數腳本的日誌記錄在放置在這裡時已被刪除(以及更改連接埠和刪除使用者/主機)。大多數日誌行只是日期>> sshfsmanager.log

本機VM運行ubuntu 18.04.5,遠端伺服器是運行gentoo 5.10.27的共用VPS

相關內容