Skip to content

Instantly share code, notes, and snippets.

@Pistos
Created September 4, 2011 21:21
Show Gist options
  • Select an option

  • Save Pistos/1193532 to your computer and use it in GitHub Desktop.

Select an option

Save Pistos/1193532 to your computer and use it in GitHub Desktop.
unicorn-killer.rb
puts "[#{Time.now}] starting"
raw = `ps aux | egrep 'Sl.*unicorn worker.*0e.pist0s.ca' | grep -v grep | awk '{ print $2,$5 }'`.split("\n")
unicorns = raw.map { |r|
data = r.split(' ')
if data[1].to_i > 60000 && data[0].to_i > 1
puts "[#{Time.now}] killing pid #{data[0]} for memory #{data[1]}"
system 'kill', '-s', 'TERM', data[0]
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment