Skip to content

Instantly share code, notes, and snippets.

@brianjolly
Created March 3, 2011 21:51
Show Gist options
  • Save brianjolly/853682 to your computer and use it in GitHub Desktop.
Save brianjolly/853682 to your computer and use it in GitHub Desktop.
Emergency script to kill out of control Rails processes. Thanks to /dev/urandom :(
grep_output = `ps aux | grep Rails`
kill_list = []
any_rails = grep_output.scan(/^www-480\s+(\d+)\s+(\d+.\d+).*Rails/)
any_rails.each do |process|
pid = process[0]
cpu = process[1]
if cpu.to_f > 95.0
kill_list << process
end
end
if kill_list.length > 0
kill_list.each do |process|
pid = process[0]
cpu = process[1]
`kill #{process[0]}`
`echo "#{pid} #{cpu}% killed - #{Time.now}" >> /home/hog_kills.log`
end
`/sbin/service httpd restart`
end
@brianjolly
Copy link
Author

Emergency script to kill out of control Rails processes. Thanks to /dev/urandom :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment