Skip to content

Instantly share code, notes, and snippets.

@mrowe
Created May 9, 2013 02:07
Show Gist options
  • Save mrowe/5545068 to your computer and use it in GitHub Desktop.
Save mrowe/5545068 to your computer and use it in GitHub Desktop.
The genesis of the zombie apocalypse.
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
@michaelneale
Copy link

on line 15 what happens if the tag list fails to load?

@mrowe
Copy link
Author

mrowe commented Jul 31, 2019

Like that would ever happen.

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