SSHFS - auto reconnect

I have an SSHFS mount that I can connect using the command line:

echo myPassword | sudo sshfs [email protected]:/ /media/NAS -p31337 -o workaround=rename -o password_stdin -o allow_other

which seems to mount my NAS to /media/NAS well enough.

Very occasionally the connection will be broken if there's a power or Internet outtage, and in these cases I would have to recognise this has happened and manually reconnect using the same command.

Is there a way I can get my Ubuntu Server to automatically attempt to reconnect, say every 30 seconds, if the connection goes down?

Thanks.


Solution 1:

This question is answered on https://serverfault.com/questions/6709/sshfs-mount-that-survives-disconnect/639735. I am duplicating it here.

sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 server:/path/to/mount

As explained at the Server Fault link, the ServerAliveInterval=15 option asked sshfs to check if the server is alive every 15 seconds. ServerAliveCountMax=3 allows the server to not respond for up to three alive checks. The result is that if the server is unavailable for 1 minute, sshfs will reconnect to the server.