![sshfs がロックすると自動的にリセットされ、手動で実行しない限り再マウントは失敗します。](https://rvso.com/image/192222/sshfs%20%E3%81%8C%E3%83%AD%E3%83%83%E3%82%AF%E3%81%99%E3%82%8B%E3%81%A8%E8%87%AA%E5%8B%95%E7%9A%84%E3%81%AB%E3%83%AA%E3%82%BB%E3%83%83%E3%83%88%E3%81%95%E3%82%8C%E3%80%81%E6%89%8B%E5%8B%95%E3%81%A7%E5%AE%9F%E8%A1%8C%E3%81%97%E3%81%AA%E3%81%84%E9%99%90%E3%82%8A%E5%86%8D%E3%83%9E%E3%82%A6%E3%83%B3%E3%83%88%E3%81%AF%E5%A4%B1%E6%95%97%E3%81%97%E3%81%BE%E3%81%99%E3%80%82.png)
私のサーバーにはリモートサーバーにマウントされた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 です。