Skip to content

Commit

Permalink
gbrowse_launch_aws_slaves.pl now syntactically correct
Browse files Browse the repository at this point in the history
  • Loading branch information
lstein committed Oct 31, 2012
1 parent d402762 commit e7d87f9
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions bin/gbrowse_launch_aws_slaves.pl
Expand Up @@ -9,7 +9,6 @@
use strict; use strict;
use VM::EC2; use VM::EC2;
use VM::EC2::Instance::Metadata; use VM::EC2::Instance::Metadata;
use Sys::CpuLoad;
use Getopt::Long; use Getopt::Long;


# load averages: # load averages:
Expand Down Expand Up @@ -59,8 +58,15 @@
exit 0; exit 0;


sub get_load { sub get_load {
my ($one,$five,$fifteen) = Sys::CpuLoad::load(); if (-e '/proc/loadavg') {
return $fifteen; open my $fh,'/proc/loadavg';
my ($one,$five,$fifteen) = split /\s+/,<$fh>;
return $five;
} else {
my $l = `w`;
my ($one,$five,$fifteen) = $l =~ /load average: ([0-9.]+), ([0-9.]+), ([0-9.]+)/;
return $five;
}
} }


sub adjust_spot_requests { sub adjust_spot_requests {
Expand Down Expand Up @@ -90,7 +96,7 @@ sub adjust_spot_requests {


# what to do if there are too many spot requests for the current load # what to do if there are too many spot requests for the current load
# either cancel spot requests or shut instances down # either cancel spot requests or shut instances down
while (@potential_instances > $min) { while (@potential_instances > $max_instances) {
my $i = shift @potential_instances; my $i = shift @potential_instances;
if ($i->isa('VM::EC2::Instance')) { if ($i->isa('VM::EC2::Instance')) {
warn "terminating $i"; warn "terminating $i";
Expand All @@ -102,18 +108,17 @@ sub adjust_spot_requests {
} }


# what to do if there are too few # what to do if there are too few
if (@potential_instances < $max) { if (@potential_instances < $min_instances) {
my $count = $max - @potential_instances; warn "launching a new spot request";
warn "launching $count spot requests";
my @requests = $ec2->request_spot_instances( my @requests = $ec2->request_spot_instances(
-image_id => $imageId, -image_id => $imageId,
-instance_type => IMAGE_TYPE, -instance_type => IMAGE_TYPE,
-instance_count => $count, -instance_count => 1,
-security_group => SECURITY_GROUP, -security_group => SECURITY_GROUP,
-user_data => "#!/bin/bash\n/etc/init.d/gbrowse-slave start\n", -user_data => "#!/bin/bash\n/etc/init.d/gbrowse-slave start\n",
); );
push @potential_instances,@requests;
} }
push @potential_instances,@requests;
return @potential_instances; return @potential_instances;
} }


Expand All @@ -123,8 +128,9 @@ sub adjust_configuration {
my @instances = grep {$_->isa('VM::EC2::Instance')} @potential_instances; my @instances = grep {$_->isa('VM::EC2::Instance')} @potential_instances;
my @addresses = map {$_->privateDnsName} @instances; my @addresses = map {$_->privateDnsName} @instances;
warn "Adding slaves at address @addresses"; warn "Adding slaves at address @addresses";
my @args = map {'--add'=>$_} map {"http://$_:8101", my @a = map {("http://$_:8101",
"http://$_:8102", "http://$_:8102",
"http://$_:8103"} @addresses; "http://$_:8103")} @addresses;
my @args = map {('--add'=> "$_") } @a;
system 'sudo','gbrowse_add_slaves.pl',@args; system 'sudo','gbrowse_add_slaves.pl',@args;
} }

0 comments on commit e7d87f9

Please sign in to comment.