Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am running 12.04 LTS. There are a number of shared resources that I use that are housed remotely on a local server. When disconnected from the network (on say a network, or router failure), I would like to dynamically archive, rename, and un-archive directory backups to continue the use of these shared assess until the network is restored.

Is there a preferred method of gaining this data and triggering scripts or other system actions when the connected state changes?

EDIT: After some additional research I see that there is the possibility of doing this with udev from Triggering an action when a specific volume is connected. However is this the best way? Also is there an alternative tool for udevinfo? It does not appear to be part of the package.

share|improve this question
    
If you need some fancy way of detecting when the remote servers are down, the folks at Server Fault might be better help. –  Gilles Mar 19 '13 at 21:19
    
nothing fancy needed. Just looking for a low resource way of detecting it. I think your answer below should do it –  Simianspaceman Mar 19 '13 at 21:29
add comment

2 Answers 2

When a network interface is brought up or down, scripts under /etc/network are executed. You can put your script in /etc/networking/if-down.d or in /etc/networking/if-post-down.d. The former runs with the interface still available while the latter runs with the interface already disconnected; of course, the interface may have been brought down automatically because the local network failed, in which case you won't be able to use the network even from if-down. The script gets information about the network interface through environment variables as documented in the interfaces(5) manual page. Be sure to react only to a loss of the interface(s) that matter.

If the network connection drops due to a failure somewhere outside the local link, or even because the first router stops working properly, your machine won't be notified. To detect such loss of service, you need to run some kind of heartbeat service that periodically checks that the remote server is still alive and responding. There isn't a one-size-fits-all solution here because different use cases call for different thresholds between “the network/server is slow” and “the network/server is down”. Also, determining whether the server is alive is application-specific; it can be a ping, or an HTTP request, or a keepalive packet on a TCP connection, etc.

share|improve this answer
    
I ideally want to have contingency for both. The heartbeat idea is a good one, in the case of a server but not whole network failure. Do you recommend a cron script to run every minute or so and ping the server? –  Simianspaceman Mar 19 '13 at 21:26
    
@Simianspaceman No, the heartbeat program should be running continuously. You can't tell if a server is down instantly: you wouldn't want to drop everything just because a router ate a TCP packet or two and there was a few seconds' lag (except within a high-availability datacenter, but I'm guessing you wouldn't be asking here if that was your use case). Whether pinging is the right thing depends on your scenario, for example it won't react to a firewall misconfiguration that makes it drop pings, or to a crashed server process. –  Gilles Mar 19 '13 at 21:30
    
That is correct. I am in a small office with a server sharing software on networked machines. The idea is to swap over to backups and continue to work in case of a central server or network failure. –  Simianspaceman Mar 19 '13 at 21:36
1  
@Simianspaceman I know Apache has failover support, but don't ask me how this works, it's not something I work on. Since your goal is availability, the best test is to make legitimate requests and failover if they fail (or take unreasonably long). –  Gilles Mar 19 '13 at 21:46
add comment

I sometimes find the if-up/down unreliable for the reasons Gilles mentioned. This simple custom script works well for me: https://help.ubuntu.com/community/AutomaticallyMountNFSSharesWithoutAutofsHowto

share|improve this answer
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.