Skip to content

Instantly share code, notes, and snippets.

@KINGSABRI
Created April 14, 2012 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KINGSABRI/2387616 to your computer and use it in GitHub Desktop.
Save KINGSABRI/2387616 to your computer and use it in GitHub Desktop.
OK Client
require 'socket'
require 'logger'
# OK Client
def logger
# Creat Log file with rotation
log = Logger.new('status.log', 10, 1024000) # Filename: log.txt , Number of rotation: 10 , Rotation Size= 125MB
end
def status
host = "127.0.0.1"
begin
client_ok = TCPSocket.open(host ,2000)
if client_ok.recv(1024).chomp.inspect.include? "OK"
puts "Server #{host}: UP"
logger.info "Server #{host} : UP"
end
rescue #Exception => e
puts "OMG! Server is down"
logger.fatal "Server #{host} : DOWN!"
exit
end
end
status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment