From 22006c8154d02da7d23ddd298150f8aa59042349 Mon Sep 17 00:00:00 2001 From: Ari Lerner Date: Mon, 12 Oct 2009 17:28:25 -0700 Subject: [PATCH] Added cloud reboot to cycle instances --- bin/cloud-reboot | 23 ++++++++++++++ .../ec2/helpers/elastic_auto_scaler.rb | 2 +- lib/poolparty/cloud.rb | 31 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 bin/cloud-reboot diff --git a/bin/cloud-reboot b/bin/cloud-reboot new file mode 100755 index 000000000..d16f16e5e --- /dev/null +++ b/bin/cloud-reboot @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby +$:.unshift(File.dirname(__FILE__) + "/../lib") +require "poolparty" + +require 'git-style-binary/command' + +GitStyleBinary.command do + banner <<-EOS +Usage: #{$0} #{all_options_string} + + Cycle through nodes in the cloud and wait for the autoscaler to reboot +EOS + + short_desc "Cycle the instances" + + run do |command| + + @loaded_clouds.each do |cld| + cld.reboot! + end + + end +end \ No newline at end of file diff --git a/lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb b/lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb index 5664cb79d..93496c537 100644 --- a/lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb +++ b/lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb @@ -41,6 +41,7 @@ def teardown # cloud.nodes.each {|n| n.terminate! } delete_autoscaling_group! delete_launch_configuration! + puts "" end end @@ -75,7 +76,6 @@ def ensure_no_scaling_activities sleep 1 end end - puts "" reset! end public diff --git a/lib/poolparty/cloud.rb b/lib/poolparty/cloud.rb index a6d0e8294..0adc973fa 100644 --- a/lib/poolparty/cloud.rb +++ b/lib/poolparty/cloud.rb @@ -191,6 +191,37 @@ def teardown #TODO: keypair.delete # Do we want to delete the keypair? probably, but not certain end + def reboot! + orig_nodes = nodes + num_nodes = nodes.size + + if autoscalers.empty? + puts <<-EOE +No autoscalers defined + Launching new nodes and then shutting down original nodes + EOE + # Start new nodes + expand_by(num_nodes) + # Terminate the nodes + orig_nodes.each do |node| + node.terminate! + end + else + # Terminate the nodes + orig_nodes.each do |node| + node.terminate! + puts "----> Terminated node: #{node.instance_id}" + # Wait for the autoscaler to boot the next node + puts "----> Waiting for new node to boot via the autoscaler" + loop do + reset! + break if nodes.size == num_nodes + sleep 1 + end + end + end + end + def compile! build_tmp_dir unless chef_repo.nil? end