Skip to content

Instantly share code, notes, and snippets.

@halcyonCorsair
Forked from mrowe/stopinator.rb
Created May 28, 2013 07:35
Show Gist options
  • Save halcyonCorsair/5661091 to your computer and use it in GitHub Desktop.
Save halcyonCorsair/5661091 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