![當 sshfs 鎖定時自動重置,重新掛載失敗,除非手動完成](https://rvso.com/image/192222/%E7%95%B6%20sshfs%20%E9%8E%96%E5%AE%9A%E6%99%82%E8%87%AA%E5%8B%95%E9%87%8D%E7%BD%AE%EF%BC%8C%E9%87%8D%E6%96%B0%E6%8E%9B%E8%BC%89%E5%A4%B1%E6%95%97%EF%BC%8C%E9%99%A4%E9%9D%9E%E6%89%8B%E5%8B%95%E5%AE%8C%E6%88%90.png)
我的伺服器上有 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