Adam Holt's Blog

Ruby on Rails, PHP, Javascript and Web Development

Ruby to the Rescue!

Lately at my work we’ve been having some real problems with a clients servers, basically PHP has been seg faulting during memory allocation (for an as yet unknown reason) and apache processes keep getting stuck because of it.

So far the client is refusing to do anything to fix it at the moment (they dont want to screw with the servers this close to christmas), so that leaves me and a couple of the other guys having to go through all 9 servers every couple of hours to try and find which server has seg faulted, and then restart the stuck apache process, a little tedious i think you’ll agree.

So last night i decided to hack up a little ruby script to do the hunting work for us and i thought id share it with you guys :D

require 'rubygems'
require 'net/ssh'
 
hosts = %w( web-server.test.com )
 
puts "--------------------------------"
hosts.each do |host|
  Net::SSH.start(host,"********",:password => "********", :port => 22) do |ssh|
    hostname = ssh.exec!("hostname")
    puts "Connected To #{hostname}"
    puts "Searching for Segmentation Faults"
    ssh.exec!("sudo tail -n100 /var/log/httpd/error_log | grep 'Segmentation'") do |channel, stream, data|
      if stream == :stdout
        puts data.split("\n").first
      end
    end
    puts "Disconnecting From #{hostname}"
    puts "--------------------------------"
  end
end

Obviously, it’s dead simple, basically connects to an arbitrary amount of servers and tail the last 100 lines from the apache error log, and spit out any that have ‘Segmentation’ in them! No more manual searching of log files!

I think the next thing on the list is to have it graceful the apache server automatically on finding a segfault.

An Introduction To Me

This blog has been sitting here, unused and alone for a quite some time now, so i thought its about time i got off my lazy arse and actually start writing on it, hopefully it will turn into a regular thing.

So i thought id start off with a quick introduction to me (how original eh?)

My name is Adam Holt, i am 21 and i live in Manchester in the UK with my girlfriend (Jenny Core) and my two best friends.

I am primarily a PHP web developer but currently chomping at the bit to do more ruby (and rails) work.

I currently work for a company called Kudos Web Solutions in the northern quarter of Manchester.

My hobbies are online gaming, collecting lots of gadgets that i couldn’t ever possibly need, having the occasional kick about with friends, developing web applications and hacking up bits of code to figure out how they work.

So, thats a brief history of me, if you want to get in contact with me for any reason, you can hit me up on Twitter, Facebook or email me at ads.noob@gmail.com