sshfs がロックすると自動的にリセットされ、手動で実行しない限り再マウントは失敗します。

sshfs がロックすると自動的にリセットされ、手動で実行しない限り再マウントは失敗します。

私のサーバーにはリモートサーバーにマウントされた2つのローカルディレクトリがあります。ローカルは接続を維持し、 autossh -M 23 -R 24:localhost:22 user@serverリモートはdirs-sshfs.shでマウントします。

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 も実行しましたが、機能しませんでした。テスト スクリプト (testsshfs2.sh)には、すべてがマウント/動作しているかどうかをすばやく簡単に確認できるように作成されたものが./sshfs-restart.sh &含まれています。ls; echo; ls dir1; echo; ls dir2; echo; date; echo

これは sshfsmanager.sh で、while ループ内で sleep コマンドを使用してローカル サーバーから実行されます。将来的には 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 です。

関連情報