tags:

views:

76

answers:

4

There are 2 servers, they need to know the status(live oe dead) each other. my method is a long tcp connecting, Is there any better method? thanks.

+2  A: 

I`m no sysadmin, but why not simply use nmap or the likes to check if the ports your servers are listening on are still open? I mean, you simply want to know if they are alive or dead, right? When one of your server crashes, the port shouldn´t be open anymore.

tombom
good! http://github.com/sophsec/ruby-nmap
why
A: 

system('ping -c 5' + host)

mazianni
A: 

It sounds to me like you are looking for some sort of cluster/heartbeat functionality. If that is the case, maybe the Linux-HA project may help (never used it myself).

Brian
+2  A: 
require 'ping'

def alive?(host)
 Ping.pingecho host, 15, 80
end

Ping.pingecho accepts three arguments, the hostname or ip, timeout period and a port number. You can find more info about the subject here.

Maran