-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathresumeASGProcesses.pl
59 lines (49 loc) · 2.52 KB
/
resumeASGProcesses.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
$ThisDir=($0 =~ /^(.+)[\\\/]/)? $1 : "." ;
require "$ThisDir/ClusterInitVariables.pl";
print "DEBUG: Entering resumeASGProcesses.pl name=\"$name\", master_name=\"$master_name\", other_name=\"$other_name\", region=\"$region\"\n";
if ( ! defined($stackname) || ($stackname=~/^\s*$/) ){
if (defined($master_name) && ($master_name!~/^\s*$/) ){
$stackname=$1 if $master_name =~ /^(.+)\-\-/;
}
elsif (defined($other_name) && ($other_name!~/^\s*$/) ){
$stackname=$1 if $other_name =~ /^([^,]+)\-\-/; # [^,]++ is used here because there could be more than 1 name separated by commas.
}
}
print "\$asgnames=aws autoscaling describe-auto-scaling-groups --region $region\|egrep AutoScalingGroupARN\|sed -e \"s/^.*autoScalingGroupName//\" -e \"s/\", *//\"\|egrep $stackname\n";
$_=`aws autoscaling describe-auto-scaling-groups --region $region`;
# 2 greps. Inter-most gets only lines containing both 'AutoScalingGroupARN' and $stackname. The out-most grep
# extracts just the ASG name. All names are put in @asgnames.
@asgnames=grep($_=extractASGName($_),grep(/\"AutoScalingGroupARN\":.+$stackname/,split(/\n+/,$_)));
print "asgnames=(",join(",",@asgnames),")\n";
sub extractASGName{
my ( $a )=@_;
local $_=$a;
s/^.*autoScalingGroupName\///;# Remove everything before ASG name
s/",\s*$//; # Remove everything after ASG name
return $_;
}
#-----------------------------------------------------------------------------------------------------
# For each autoscaling group whose name is in $asgnames, resume these processes: Launch Terminate HealthCheck
foreach my $asgname (@asgnames){
next if $asgname=~/^\s*$/;
print "aws autoscaling resume-processes --auto-scaling-group-name $asgname --scaling-processes Launch Terminate HealthCheck --region $region\n";
my $rc=`aws autoscaling resume-processes --auto-scaling-group-name $asgname --scaling-processes Launch Terminate HealthCheck --region $region`;
print "$rc\n";
}
print "appendStatement2ClusterInitVariables('\$ASGSuspended=0;')\n";
appendStatement2ClusterInitVariables('$ASGSuspended=0;');
#================================================
sub appendStatement2ClusterInitVariables{
my ($line2add)=@_;
my $save_delim=$/;
$/="";
open(IN, "$ThisDir/ClusterInitVariables.pl") || die "Can't open for input \"$ThisDir/ClusterInitVariables.pl\"\n";
local $_=<IN>;
s/\n1;\s*$//;
close(IN);
$_ .= "\n$line2add\n1;";
open(OUT,">$ThisDir/ClusterInitVariables.pl") || die "Can't open for output \"$ThisDir/ClusterInitVariables.pl\"\n";
print OUT $_;
close(OUT);
}