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です。

ベストアンサー1

おすすめ記事