Skip to content

Instantly share code, notes, and snippets.

@bhouse
Forked from halcyonCorsair/stopinator.rb
Created July 22, 2013 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhouse/6058391 to your computer and use it in GitHub Desktop.
Save bhouse/6058391 to your computer and use it in GitHub Desktop.
def ec2
Fog::Compute.new(:provider => 'AWS',
:aws_secret_access_key => ENV['EC2_SECRET_KEY'],
:aws_access_key_id => ENV['EC2_ACCESS_KEY'])
end
def tenured? (instance)
instance.created_at && (instance.created_at < Chronic.parse('50 minutes ago'))
end
def alive? (instance)
instance.state == 'running' or instance.state == 'stopped'
end
zombies = ec2.servers.select { |i| i.tags.empty? && tenured?(i) && alive?(i) }
Parallel.each(zombies, :in_threads => 15) do |zombie|
begin
puts "Terminating zombie node #{zombie.id}"
ec2.servers.get(zombie.id).destroy
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment