Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have 2 servers (linux), one for PHP application, second for static files serving. I want to mount directory from static server in application directry so I could write / read files on static server like local files.

I thought about 2 ways:

  1. NFS - old and not good when static server is far away on internet
  2. SSHFS - good but there is a problem when connection is broken, every operation in mounted directory hangs for ages and my application hangs too.

I will probobly use SSHFS but how to handle situation when sshfs hangs on broken connection?

Maby there is a better way to mount a directory from another server with ability to not hang on broken connection?

Thanks for help.

share|improve this question
add comment

2 Answers

You would be much better off just using rsync and keep the files on the application server itself syncronized with the remote server or vice versa. As you've already anticipated sshfs is not the ideal method due to dropped connection handling. Filesystem mounts that you want to be reliable should not be made over external links.

share|improve this answer
    
I will use rsync to sync files between servers but the problem still exists when my application need to read some files or just check if files exists on static server. It would be simple with sshfs when connection is fine but it would hang otherwise. I supose there is no simple way to do it right... –  piotrekkr Oct 14 '11 at 8:55
add comment

Put this in the contents of /home/{user}/.ssh/config:

Host *
  ServerAliveInterval 30
  ServerAliveCountMax 20

man ssh_config gives this explanation:

 ServerAliveCountMax
         Sets the number of server alive messages (see below) which may be sent
         without ssh(1) receiving any messages back from the server.  If this
         threshold is reached while server alive messages are being sent, ssh
         will disconnect from the server, terminating the session.  It is impor‐
         tant to note that the use of server alive messages is very different
         from TCPKeepAlive (below).  The server alive messages are sent through
         the encrypted channel and therefore will not be spoofable.  The TCP
         keepalive option enabled by TCPKeepAlive is spoofable.  The server
         alive mechanism is valuable when the client or server depend on knowing
         when a connection has become inactive.

         The default value is 3.  If, for example, ServerAliveInterval (see
         below) is set to 15 and ServerAliveCountMax is left at the default, if
         the server becomes unresponsive, ssh will disconnect after approxi‐
         mately 45 seconds.  This option applies to protocol version 2 only.

 ServerAliveInterval
         Sets a timeout interval in seconds after which if no data has been
         received from the server, ssh(1) will send a message through the
         encrypted channel to request a response from the server.  The default
         is 0, indicating that these messages will not be sent to the server.
         This option applies to protocol version 2 only.

Adjust your values accordingly.

share|improve this answer
    
The problem is: when remote server is unavailable and I want to do something on files mounted using sshfs, it takes really long time to get error message saing that operation won't work. I don't think that server ServerAliveInterval or ServerAliveCountMax help when server is down. –  piotrekkr Apr 16 '13 at 8:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.