Created
March 27, 2009 18:47
-
-
Save solisoft/86819 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
environment = "www" | |
mongrel_rails = "/usr/local/bin/mongrel_rails" | |
result = `cd #{environment}/current && #{mongrel_rails} cluster::status`.split("\n") | |
result = result.map{|r| r unless r == ""}.compact | |
check = result.map{|r| r =~ /^found/}.compact | |
pids = [] | |
ports= [] | |
result.each do |r| | |
pid = r.scan /pid (\d+)$/ | |
pids << pid.to_s.to_i if pid.size > 0 | |
port= r.scan /port (\d+)/ | |
ports << port.to_s.to_i if port.size > 0 | |
end | |
if check.size == result.size | |
puts "Server OK" | |
else | |
puts "Restarting mongrel Server" | |
`kill -9 #{pids.join(" ")}` if pids.size > 0 | |
ports.each do |port| | |
pid = `pgrep -f #{port}` | |
`kill -9 #{pid}` if pid != "" | |
end | |
`rm #{environment}/current/tmp/pids/*` | |
`cd #{environment}/current && #{mongrel_rails} cluster::restart` | |
file = File.new("checkapp.log", "a") | |
file.write("Restarting mongrel serveur\n") | |
file.write("==========================\n") | |
file.write("#{Time.now}\n") | |
file.write("#{result.inspect}\n") | |
file.write("#{ports.inspect}\n") | |
file.write("#{pids.inspect}\n\n") | |
file.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment