This is a late reply but more of a headache now. The cron is not doing the job. The rate that client uploads to the site crashes the site far to fast now and it seems the cron does not pick up the mess.
here is the old script I found here and followed to the t. It would work in simulation testing but when I leave it to the real heavy duty world I come back the next day to a dead server and lots of angry people.
As a customer I need to know what other options I have besides cron if not God ?
Old script
#!/usr/local/bin/ruby
require "net/smtp"
username = "name"
application = "app"
rails_dir = "/home/#{username}/#{application}/"
ruby = "/usr/local/bin/ruby"
mongrel = "/usr/local/bin/mongrel_rails"
number_of_mongrels = 7
mongrel_port = ***
#number_of_runningdruby = 1
to_email = "fake@gmail.com"
from_email = "fake@gmail.com"
email_subject = "Mongrel Server Status"
def send_email(from, to, subject, message)
msg = <<END_OF_MESSAGE
From: #{from}
To: #{to}
Subject: #{subject}
#{message}
END_OF_MESSAGE
Net::SMTP.start('localhost') do |smtp|
smtp.send_message msg, from, to
end
end
# restart mongrel. need to chdir to app folder first
def restart_mongrels
end
Dir.chdir(rails_dir)
f = IO.popen("ps -edf | grep #{username} | grep '#{mongrel}' | grep -cv grep")
g = IO.popen("ps -edf | grep #{username} | grep 'upload' | grep -cv grep")
number_of_processes = f.readline.chomp.to_i
number_of_druby = g.readline.chomp.to_i
if number_of_processes == number_of_mongrels then
# everything is OK
message = Time.new.gmtime.to_s + "> #{number_of_mongrels} mongrels are running as expected."
puts message # print as well as email message
#send_email(from_email, to_email, email_subject, message)
else
puts Time.new.gmtime.to_s + " > Mongrels are not running.."
# kill existing mongrels (if any) then remove logs
system("killall -usr1 mongrel_rails &> /dev/null") # do not want to see output from this command
system("rm log/mongrel.*.pid")
# start new mongrel processes
for number in (0..number_of_mongrels-1)
port_number = mongrel_port + number
system("#{ruby} #{mongrel} restart -d -e production -p #{port_number} -P log/mongrel.#{port_number}.pid -c #{rails_dir} --user #{username} --group #{username}")
puts "..started mongrel instance on port #{port_number}"
end
message = Time.new.gmtime.to_s + "> Mongrel was not running. It has now been started."
puts message
send_email(from_email, to_email, email_subject, message)
restart_mongrels
# if restarted, send restarted message
# send_email(from_email, to_email, email_subject, message)
end
2007-10-31 06:46 AM