Last active
January 18, 2019 01:59
-
-
Save ShawInnes/1926fc61ee6d591813105c4eda7daad8 to your computer and use it in GitHub Desktop.
Auto-shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export EC2_HOME=/opt/aws/apitools/ec2 | |
export JAVA_HOME=/usr/lib/jvm/java | |
PATH=/bin:/usr/bin::/usr/local/bin | |
source /usr/local/bin/jenkins-backup /var/lib/jenkins s3://${{self:custom.s3BucketName}}/jenkins-`date +%Y%m%d%H%M.tar.gz` >> ~/jenkins.cron.log 2>&1 | |
asijson="$(aws autoscaling --region ap-southeast-2 describe-auto-scaling-instances --instance-ids `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`)" | |
asgn="$(echo $asijson | jq -r '.AutoScalingInstances[] | @text "\(.AutoScalingGroupName)"')" | |
sleep 20 && aws autoscaling set-desired-capacity --region ${AWS::Region} --auto-scaling-group-name $asgn --desired-capacity 0 --honor-cooldown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment